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

南笙酒味 提交于 2019-12-07 02:16:52

问题


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.

来源:https://stackoverflow.com/questions/32675855/avplayers-video-and-audio-become-out-of-sync-after-pausing-and-then-resuming-vi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!