iphone - iOS 多个 AVPlayer 对象导致音频/视频同步丢失

标签 iphone ipad synchronization avplayer

我一直在尝试在我的应用程序中使用两个不同的 AVQueuePlayer 对象。第一个播放器播放一系列通过网络传输的短视频剪辑。第二个对象仅播放一个视频,但长度要长得多。它也是流式传输的。我已验证所有剪辑都具有正确的音频/视频同步。

我注意到,如果我在事先创建了另一个 AVPlayer 对象后创建了另一个对象,则第二个播放器中的音频/视频同步会丢失。音频在大约 800 毫秒 - 1500 毫秒之间过早播放。

我尝试了很多方法,包括在清理第一个播放器和分配第二个播放器之间添加延迟、删除对 AudioSession 代码的所有调用等。这些似乎都没有帮助。音频偶尔会同步,但这种情况实际上只发生大约十分之一。

还有其他人看到过同样的行为吗?有谁知道如何解决这个问题吗?

感谢任何可以提供帮助的人!

最佳答案

我自己也面临着同样的问题。我在 AVPlayerLayer 文档中发现了一些信息:

During playback, AVPlayer may compensate for temporal drift between its visual output and its audible output to one or more independently-clocked audio output devices by adjusting the timing of its associated player layers. The effects of these adjustments are usually very small; however, clients that wish to remain entirely unaffected by such adjustments may wish to place other layers for which timing is important into independently timed subtrees of their layer trees.

You can create arbitrary numbers of player layers with the same AVPlayer object. Only the most-recently-created player layer will actually display the video content on-screen.

不幸的是,我还没有将其解读为实际的代码,但我认为它可能会帮助您指明正确的方向。如果您确实想出了解决方案,请在此处发布,我也会这样做。

关于iphone - iOS 多个 AVPlayer 对象导致音频/视频同步丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5002926/

相关文章:

iphone - 如果我的 iPhone 应用程序使用 Bonjour,我是否需要与 Apple 签订许可协议(protocol)?

ios - 在 WatchKit 中将 iOS 应用带到前台

iphone - 更改 iPad 方向时 Xcode 4.5 出现问题

ios - UISwitch:使触摸区域大于默认触摸区域

swift - 在 OSX 上快速处理同步

c++ - 如何安全地将包含的对象(菜单项)与需要容器(菜单)的 API 同步?

java - 如何同步线程

iphone - 使用 NSLog 打印 NSData

iphone - sscanf 在 iPhone OS 3.1.2 上是线程安全的吗?

iphone - 图片没有上传到网络服务