Sound not working in iPhone Simulator?
Asked Answered
B

9

55

Somehow my iPhone Simulator is unable to play sounds. First an app I'm working on using AudioServicesPlaySystemSound() stopped working.. I spent a while debugging this but sound is still working on the iPhone when I run the app on the device. I get the same results with other iPhone apps such as the sample Crash Landing app.

I can't find a sound setting anywhere in the simulator or Xcode preferences. I've tried resetting the simulator through "Reset Content and Settings" menu item to no avail.

Bess answered 19/11, 2008 at 16:5 Comment(0)
T
79

On your Mac, go to System Preferences > Sound > Sound Effects and then uncheck and recheck "Play user interface sound effects".

You need to re-activate your system sounds, see the end of this page.

Twister answered 12/2, 2009 at 23:55 Comment(6)
Thanks -- this worked for me. Go to System Preferences > Sound > Sound Effects and then uncheck and recheck "Play user interface sound effects". The iPhone Simulator suddenly started playing sound again after this.Sext
thanks it works for me too! :) with iPhone SDK 3.2 and OSX 10.6Perloff
When there are multiple sound output attached, please make sure the select the right output device in "Play sound effects through" drop option.Checkmate
Discussion on Apple.com has been deletedScriptorium
The link is broken. So sad.Mize
Killing the simulator completely (pressing cmd+Q) then re-running the app fixed it for me!Ingather
L
23

I had no sound in the simulator, so I tested it with mobile safari and tried playing an mp3: No sound!

All the above tips didn't help. Eventually, I changed my INPUT source from the virtual soundflower device to Line-In, and the Simulator worked!

So, even if the app wasn't using input, it didn't work well with Soundflower.

Lowman answered 10/7, 2010 at 11:30 Comment(3)
worked for me too -- I'd switched input to a USB headset and needed to switch back to Line-In. +1.Madelinemadella
Wow.. banged my head for hours on this one on Xcode 4.2 with Lion 10.7.3! Definitely need to file a bug with apple on this! ThanksFiertz
WORKED This is soooo not intuitive. I would never have thought to check the INPUT. Now I can get the sound program tested (sigh).Songful
A
15

My symptoms were:

  • My app's sounds played in iPad simulator, but not in iPhone simulator
  • iPhone simulator sound was otherwise OK, e.g. YouTube in Safari

It appears there's a bug in Silent Mode for the iPhone simulator. To work around this, I turned Silent Mode on and then off again:

  1. In Simulator menu, turn on Window > Show Device Bezels.
  2. The bezel shows hardware buttons. Find the silent mode switch, and click it twice.
  3. Hide the bezels again, if preferred.

enter image description here

Thanks to Benzy Neez's answer for the hint that the issue related to AVAudioSession.Category.ambient.

Adenoid answered 17/5, 2023 at 6:24 Comment(1)
Nice one! The workaround of cycling silent mode seems to last for the lifetime of the simulator session, but needs to be done again after re-starting the simulator.Hayleyhayloft
A
4

I've seen this problem after my update from OSX10.5.7 to 10.6.2

And I made the following changes to make the simulater sing again: Goto "Applications/Utilities" and run "Audio MIDI Setup", then change midi format from 48000 to 44100.

Amphimixis answered 8/12, 2009 at 6:13 Comment(1)
Thanks for the tip - my sound is still working in 10.6.2, but it's good to know that this fixed your issue.Bess
I
3

I've found sound to be very inconsistent in the simulator (2.1 SDK). Sometimes it works, sometimes it doesn't. Even when it does work, it's usually very choppy and distorted (when playing audio files such as mp3).

A few things to remember:

  • call AudioSessionInitialize as soon as your app finishes launching
  • set the kAudioSessionProperty_AudioCategory property for the session via AudioSessionSetProperty (with a value such as kAudioSessionCategory_MediaPlayback)
  • call AudioSessionSetActive(YES)

Of course when all else fails, just run it on your hardware!

EDIT: Now that the 2.2 SDK has been released, I haven't had any problems with sound in the simulator. They must have fixed the bugs! I highly recommend you upgrade to the 2.2 SDK.

Iloilo answered 19/11, 2008 at 19:47 Comment(0)
P
3

OpenAL not working on the simulator was fixed with the 2.1 SDK. Make sure Active SDK and Active Executable are set to 2.1.

By the way, make sure you're using the last version of CrashLanding (v1.8). Some nasty leaks in SoundEngine were fixed recently.

Pyroelectricity answered 20/11, 2008 at 1:53 Comment(0)
H
2

if reactivating system sounds didn't work for you try this: launch audio-midi-setup, then configure your "built in output" to use 44.100Hz, 2 channels, 24 bits. (from http://www.cocos2d-iphone.org/forum/topic/4159)

somehow after a few days, my iphone simulator now wants 48.000Hz, 2 channels, 24 bits. just play with it for a bit and be warned that it might change randomly when plugging in headphones, going to standby, restarting, etc.

and here's a an off-topic hint: when you plug headphones into your iphone/ipad the buffer size might double (e.g. from 512bytes to 1024 bytes), make sure you don't rely on the buffersize you requested!

Hooge answered 12/6, 2010 at 21:26 Comment(0)
H
1

Here are two other possible reasons why sound might not play on simulator devices:

  1. With Xcode 14.2 and simulators running iPadOS 16 / iOS 16, I noticed that sound was playing on iPad simulators, but not iPhone simulators. It turned out that this was related to the AVAudioSession.Category being set on the AVAudioSession. If the category is .ambient then sound plays on iPad but not iPhone simulators, if the category is .playback then it plays on both. Interestingly, this does not seems to be a issue for iOS 15, here .ambient category plays on iPhone simulators too.
  2. If you are calling AVAudioPlayer.play(atTime: TimeInterval) then the TimeInterval you pass in must be later than the device's current time. Passing 0 will not work and just plays nothing. Even passing a value > 0 may play nothing, you need to add the time offset to the deviceCurrentTime on the player. See the associated documentation for an example. This applies to real devices too of course, not just simulators.
Hayleyhayloft answered 20/1, 2023 at 10:41 Comment(1)
Thank you! Reason 1 was the problem for me. Worked around by cycling Silent Mode, posted as a separate answer.Adenoid
C
0

I'm encountering this issue while running a watchOS simulator. In my case, the following worked:

  • Close the simulator in which the sound doesn't work.
  • Open another watchOS simulator.
  • Close it and reopen the original one.
Cephalo answered 21/12, 2022 at 15:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.