Paused Avplayer resumes when app comes to foreground

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!

A huge problem. It's amazing nobody else has mentioned it!


Nobody found a solution?

I also got this issue too,
Has anyone resolved it yet ? Pls help me to fix it.
Please file a bug report through Feedback Assistant along with sysdiagnoses to help debug this issue. Thanks.

Facing the same issue ... This is worked for me as a workaround -> Set an URL with an empty file path:

player?.url = URL(fileURLWithPath: "") // file URL with empty string prevents player from playing when app goes into foreground

This one also worked for me: player?.remove()

This also worked, call this once the VC get dismissed:

player?.remove()

Paused Avplayer resumes when app comes to foreground
 
 
Q