How do you use AVAudioPlayer to play music while in the background?

倾然丶 夕夏残阳落幕 提交于 2020-01-24 09:40:26

问题


I currently use AVAudioPlayer to play music while in the foreground, but when I press the home button my application goes to the background and the music stops. I set the category for my AVAudioSession to AVAudioSessionCategoryPlayback and set active to YES. Additionally, I added the audio key to UIBackgroundModes in my Info.plist.

Is there anything else I need to do to enable background music playback?


回答1:


There's apparently a bug in the simulator - it doesn't work there, while it works fine on the device.

(Edit: and by "doesn't work" I mean the sound stops when the app enters background, yet the player's status remains "playing" and it seems to keep "playing", although you can't hear it).



来源:https://stackoverflow.com/questions/3421128/how-do-you-use-avaudioplayer-to-play-music-while-in-the-background

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