开发者

How to debug a AVAudioPlayer play failure?

开发者 https://www.devze.com 2022-12-19 16:54 出处:网络
I\'m using an AVAudioPlayer to play a mono AIFF file from my app\'s Documents directory. On the simulator, [player play] returns YES and I hear the file playing. On the device the play method returns

I'm using an AVAudioPlayer to play a mono AIFF file from my app's Documents directory.

On the simulator, [player play] returns YES and I hear the file playing. On the device the play method returns NO and nothing happens. I grabbed the file via the Organizer - it plays back fine on my Mac and seems to be well-formed. I realize the simulator can access codecs that aren't available on the iPhone, but that shouldn't matte开发者_如何学运维r in this case, should it?

I'm at a loss as to how to debug this. Any suggestions?


I asked this question on Apple's forum and someone there asked if I had activated an Audio Session. I hadn't, and doing so fixed my problem.


Make sure you do not use an absolute path to the audio file. When you move to device, the paths change. You need to get the path to the documents folder using the standard methods and then add the relative path to your audio file. That way you get a correct path regardless of the hardware or other changes.


Create a delegate to the audio player, and override -audioPlayerDecodeErrorDidOccur:error: to see if any error happens.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号