5

On XCode 6, everything works well on device, but on simulator, sound is not played.

There is my swift code :

var url =  NSURL(string: "http://my.url.com/sound.mp3")
var data = NSData(contentsOfURL: url!)
// Removed deprecated use of AVAudioSessionDelegate protocol
AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, error: nil)
AVAudioSession.sharedInstance().setActive(true, error: nil)
self.player = AVAudioPlayer(data: data, error: nil)
self.player.prepareToPlay()
self.player.delegate = self
self.player.volume = 1
self.player.play()

There is the log :

ERROR:     98: Error '!obj' trying to fetch default input device's sample rate

ERROR:     100: Error getting audio input device sample rate: '!obj'

WARNING:   230: The input device is 0x0; '(null)'

WARNING:   234: The output device is 0x26; 'AppleHDAEngineOutputDP:3,0,1,1:0:{2D4C-092D-00000000}'

ERROR:     400: error '!obj'

ERROR:     113: * * * NULL AQIONode object

ERROR:     180: EXCEPTION thrown ('!dev'): -

ERROR:     703: Can't make UISound Renderer

ERROR:     >aqsrv> 70: Exception caught in (null) - error -1

ERROR:     180: EXCEPTION thrown ('!dev'): -

ERROR:     >aqsrv> 70: Exception caught in (null) - error -1
Kevin ABRIOUX
  • 16,507
  • 12
  • 93
  • 99

4 Answers4

5

I was having this problem, the comment from @Matti Jokipii, helped me a lot.

You need to have a sound input enabled, so your Mac doesn't give you the null exception.
Go To System Preferences > Sound. And Check you have some input connected. If not, you will have to add a microfone, and re-rerun the app.

enter image description here

Community
  • 1
  • 1
4

I had this problem. Just quit and start again to Simulator.

ali ozkara
  • 5,425
  • 2
  • 27
  • 24
1

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.

Community
  • 1
  • 1
Kampai
  • 22,848
  • 21
  • 95
  • 95
  • 7
    This answer is incorrect. The simulator can play sounds. The probable cause to the error is that the Mac doesn't have a built in microphone, therefore the input device is null. This never happens on a real iPhone or iPad device of course that have a fixed built in input. A workaround for this problem is to make OS X show an input device i.e. plug something to the audio line in. – Matti Jokipii May 11 '15 at 21:14
  • 1
    Sometimes restart the simulator could solve the problem. – Johnny Jan 06 '18 at 14:11
0

The answers already posted here led me in the right direction, but I also had to choose an "Audio Input" other than the default microphone on the simulator itself. I chose the microphone on my headset, and then I was able to play Audio using the Web Audio API from Safari in the simulator.

Got to I/O -> Audio Input -> Select a microphone.

You may also have to restart the simulator.

Instructions on how to change the Audio Input settings on the iOS simulator

John
  • 10,165
  • 5
  • 55
  • 71