How to debug AVAudioPlayer playback loss?

I use AVAudioPlayer to play a monaural AIFF file from the application's document directory.

In the simulator [player playback], YES is returned, and I hear that the file is playing. On the device, the playback method returns NO, and nothing happens. I grabbed the file through the Organizer - it plays perfectly on my Mac and seems to be well formed. I understand that the simulator can access codecs that are not available on the iPhone, but that doesn't matter in this case, does it?

I do not understand how to debug this. Any suggestions?

+4
source share
3 answers

I asked this question on the Apple forum, and someone there asked if I activated an audio session. I did not do this and I fixed my problem.

+2
source

Create a delegate for the audio player and override -audioPlayerDecodeErrorDidOccur:error: to see if any error has occurred.

0
source

Make sure that you are not using an absolute path to the audio file. When you go to the device, the paths change. You need to get the path to the document folder using standard methods, and then add the relative path to your audio file. Thus, you get the right path, regardless of equipment or other changes.

0
source

Source: https://habr.com/ru/post/1300273/


All Articles