开发者

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

开发者 https://www.devze.com 2023-01-10 16:58 出处:网络
I curre开发者_开发问答ntly 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

I curre开发者_开发问答ntly 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?


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).

0

精彩评论

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

关注公众号