IOS 10.0
I am using AvPlayer to play mp3 files hosted on Internet. In my app I am calling avplayer.pause() to explicity pause the content and the content pauses. Then I press the "home" button on the phone to move the app to the background and I cannot hear content. So far so good. (I have following set in plist to enable background audio mode).
<key>UIBackgroundModes</key>
<array>
<string>audio</string>
</array>
Now when I click on the app again, the observer I have set on avPlayer and avPlayer.currentItem gets triggered automatically in following order:
AvPlayerItem status goes to "Ready To Play"
AvPlayer reports rate = 1
... and the audio starts playing automatically!!!!
which is not the expected behavior nor desired user experience.
I tried doing avplayer.pause() using some checks in AppDelegate.applicationWillEnterForeground but that doesn't help either. Looks like iOS itself is trying to resume session.
Can't seem to figure out how to stop this. Found this thread on stackoverflow: http://stackoverflow.com/questions/17526221/paused-audio-starts-playing-automatically-on-applicationwillenterforeground
but I think recommendations there are not correct.
Any help is truly appreciated!