This is the case: I made an app using the Audio Streamer library that reads an audio file from a remote server, but I find a problem only if I do this:
- Launch the app
- Start a Podcast (audio stream)
- Pause it
- Put the app on the background (home button)
- Lock the phone
- Unlock it
- Reactivate the app
And only then, my stream will be stopped. I am attempting to reach the paused state, but could not get it done.
This happens only if I put the app in background, if not and I lock/unlock the iPhone, everything is alright again. If I pause the stream then put the app into background (Home button) and then the app is resigned from background-state, everything is OK.
So, this problem only occurs if these two things happen: App sent to b开发者_运维问答ackground + Lock/unlock the iphone
does it use AVAudioPlayer under the hood? If so you need to handle the AVAudioPlayerDelegate protocols:
- (void) audioPlayerBeginInterruption: (AVAudioPlayer *) player {
and
- (void) audioPlayerEndInterruption: (AVAudioPlayer *) player {
.. methods. Essentially use the first to store the fact that the AVAudioPlayer was stopped due to an interruption, and the second to start it off again. Fiddly, but unfortunately neccessary.
Here's a link https://developer.apple.com/documentation/avfoundation/avaudioplayerdelegate
精彩评论