iOS多个AVPlayer对象导致音频/视频同步丢失 [英] iOS Multiple AVPlayer objects results in loss of audio/video sync

查看:539
本文介绍了iOS多个AVPlayer对象导致音频/视频同步丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've been trying to use two different AVQueuePlayer objects within my app. The first player plays a series of short video clips streamed over the net. The second object plays only one video, but it is much longer in length. It is also streamed. I have verified all the clips have proper audio/video sync.

我注意到的是,如果我创建一个 AVPlayer 对象,第二个播放器中的音频/视频同步丢失。音频在大约800毫秒到1500毫秒之间播放。

What I've noticed is that if I create one AVPlayer object after having created another one beforehand, the audio/video sync in the second player is lost. The audio is played between about 800ms - 1500ms too early.

我尝试了很多东西,包括在清理第一个播放器和分配第二个播放器之间增加延迟播放器,删除对 AudioSession 代码等的所有调用。这似乎没有任何帮助。音频会偶尔同步,但实际上只发生在30次中。

I've tried a number of things, including adding a delay between cleaning up the first player and allocating the second player, removing all calls to the AudioSession code etc. None of this seems to help. Very occasionally the audio will be in sync, but it really only happens about 1 in 30 times.

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

Has anyone else seen the same behavior? Does anyone know how to fix this?

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

Thanks to anyone that can help!

推荐答案

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

I'm facing the same problem myself. I came across some information in the AVPlayerLayer documentation:


在播放过程中,AVPlayer可以
补偿
之间的时间漂移它的视觉输出和可听见的
输出到一个或多个
独立时钟音频输出
设备,通过调整其
相关播放器层的时间。这些调整的效果
通常非常小b $ b;但是,希望
的客户完全不受这种
调整的影响,可能希望将其他
层的时间重要
放入
的独立定时子树中树。

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.

您可以使用相同的AVPlayer
对象创建任意数量的
播放器图层。只有最近创建的
播放器图层才会在屏幕上显示
视频内容。

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.

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

Unfortunately I haven't deciphered this into actual code but I figured it might help point you in the right direction. If you do come up with a solution then please post it here and I will do the same.

这篇关于iOS多个AVPlayer对象导致音频/视频同步丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆