AVPlayer's video and audio become out of sync after pausing and then resuming video
Asked Answered
M

0

7

I'm using AVPlayer to play videos in my app. Video playback always works perfectly, except for when you pause/resume the video. If the user presses the pause button, and then resumes the video, sometimes the audio will be ahead of the video.

The video resumes at the correct location, but the audio is ahead. It's as if when you press pause, the audio keeps running.

When they press the pause button, all I am doing is calling the pause method of the AVPlayer, and I have also tried setting it's rate property to 0.0 which is supposed to be the exact same thing according to the documentation.

I only noticed this behavior after upgrading my iPhone 6 to iOS 9. I have tested this on an iPhone 6 Simulator using iOS 8.4 and I cannot recreate this behavior, but there are usually differences when using AVPlayer on a real device versus a simulator so I can't say for 100% sure that as of right now the bug can't be recreated on iOS 8 as well.

If you look at the iOS 9 release notes, and search for "AVFoundation" you will see that some things have changed: https://developer.apple.com/library/prerelease/ios/releasenotes/General/RN-iOSSDK-9.0/

I figured that AVPlayerItem's new property canUseNetworkResourcesForLiveStreamingWhilePaused was the source of this issue but after testing, it doesn't matter whether I set this to YES or NO, the issue still happens in both cases.

At this point I have no idea why this is happening, but as of right now my best guess is that this is an iOS 9 bug.

I'm hoping that I'm not the only one experiencing this, and that someone has found a solution already, or maybe has an idea as to why this is happening. I'm open to trying and testing anything.

Thanks for the help.

Marshland answered 20/9, 2015 at 4:37 Comment(4)
No issue here. I'm only using [avplayer pause] and [avplayer play], never using the rate.Son
@Cœur Any chance you can share some of your implementation on here or Github? I can't seem to get rid of this issue.Marshland
Could you share your media file, so I can try it?Son
Having the same issue on a HLS stream, iOS 14.2. Did you fix it? ThanksAncalin

© 2022 - 2024 — McMap. All rights reserved.