Why Doesn't iOS System Sound Play in Simulator

Sound not working in iPhone Simulator?

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.

iOS Simulator does not play sound

The error occurs because you are trying to get device's sample rate from simulator, which is not possible.

Because simulator is not a hardware. Its a software.

So some hardware functionality will not able to simulated with it.

It can not do the following:

  1. Open Camera
  2. Play sounds
  3. Gyrometer
  4. Accelerometer
  5. Shake effect
  6. Receive push notifications

And many more which required device hardware acceleration.

You need to test this in real device.

System Sound plays in iPhone simulator but on iphone not playing

Here's a small detail that many developers have wasted hours upon:

Case Sensitivity

Really, it all boils down to:

  • iPhone Simulator: Case-Insensitive
  • iOS device: Case-Sensitive

So, you might have 'waterfall' in your code, but the actual sound name is 'Waterfall'. It might even be something like 'wAtErFaLl'.

This will work fine on the simulator, but not on the device - the device simply won't find the sound.

This has happened to me for everything from sounds to images to plists.

Check your Cases!

Also, AudioServices has some guidelines on what can play in the device and what can't:

Sound files that you play using this function must be: - No longer than 30 seconds in duration - In linear PCM or IMA4 (IMA/ADPCM) format - Packaged in a .caf, .aif, or .wav file

sound is playing in simulator but not on physical device

Double check the code you've posted is not falling into the catch block. You should see an error in the console if an error is produced.

do {
print("ran")
player = try AVAudioPlayer(contentsOf: url)
player?.play()
} catch let error {
print(error.localizedDescription)
}

You should also check the device is not on silent. To prevent this you can use the below that will always the play the audio as the audio sessions category will be set to .playback

do {
try AVAudioSession.sharedInstance().setCategory(.playback)
} catch let error {
print(error.localizedDescription)
}

Can't hear System Sound in simulator or on device

Don't dispose the sound until after it finishes playing. You can do something like this:

AudioServicesAddSystemSoundCompletion(soundID, NULL, NULL, (AudioServicesSystemSoundCompletionProc)AudioServicesDisposeSystemSoundID, NULL);

Slightly icky, since we're assuming that it doesn't use the Pascal calling convention (i.e. AudioServicesDisposeSystemSoundID() can handle the extra NULL argument).



Related Topics



Leave a reply



Submit