How to play sounds in locked mode on iPhone

和自甴很熟 提交于 2019-12-11 02:08:06

问题


Everybody knows the standard procedure to keep your app alive, after the user pressed the lock button (silent sound). If I start a sound with AVAudioPlayer (before the iphone is locked), the sound plays till it's end (after locking). The app is still running. If I try to start another sound while the iPhone is locked, it will never get played. All the other things work as well but the sound doesn't.

How can I play a sound while the iphone is locked?


回答1:


If the problem is that your app is doing to sleep after the screen locks, then this question is already answered here and here on SO




回答2:


I'm not sure where your problem is, but have you set up the audio category to allow mixing?

const UInt32 categoryProp = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(categoryProp), &categoryProp);

UInt32 category = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(category), &category);

const UInt32 setProperty_YES = 1;
AudioSessionSetProperty(kAudioSessionProperty_OverrideCategoryMixWithOthers, sizeof(setProperty_YES), &setProperty_YES);



回答3:


Now all works fine! I missed a log statement. It seems I flooded the audio buffer!

Thanks to all who tried to help me fixing this.



来源:https://stackoverflow.com/questions/2913185/how-to-play-sounds-in-locked-mode-on-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!