AVQueuePlayer无间隙播放和冻结 [英] AVQueuePlayer playback without gap and freeze
问题描述
我使用 AVQueuePlayer
来播放从网址加载的一系列电影。
我试图用所有<$的数组初始化播放器实例我需要玩c $ c> AVPlayerItems 。
I use AVQueuePlayer
to play a sequence of movies which are loaded from URLs.
I tried to initialize player instance with array of all AVPlayerItems
that I need to play.
player = [[AVQueuePlayer queuePlayerWithItems:playerItemsArray]
但在这种情况下 AVQueuePlayer
加载一些在开始播放之前,每个 AVPlayerItem
的初始部分。它导致令人沮丧的冻结并且应用程序在几秒钟内没有响应。
But in this case AVQueuePlayer
loads some initial part of each AVPlayerItem
before starting playback. It causes frustrating freeze and application doesn't respond for some seconds.
有可能只添加第一个 AVPLayerItem
到玩家的队列,观察它的状态并在第一个将到达结束时在队列中添加第二个项目,但在这种情况下,由于初始化和缓冲第二个 AVPlayerItem而导致两个项目的回放之间存在差距
。
There is possibility to add only first AVPLayerItem
to player's queue, observe its state and add second item in queue only when first will reach end, but in this case there will be a gap between playback of two items caused by initializing and buffering of second AVPlayerItem
.
有没有办法在没有冻结的情况下组织几个视频的无间隙播放?
我应该使用其他播放器吗?这个目的?
Is there any way to organize gapless playback of several videos without a freeze?
Should I use some other player for this purposes?
提前致谢。
推荐答案
找到解决方案。
添加新 AVPlayerItem
在队列中 AVQueuePlayer
播放器将同步等待播放器项目的初始部分将被缓冲。
When adding new AVPlayerItem
in queue of AVQueuePlayer
player will synchronously wait till initial part of player item will be buffered.
所以在这种情况下,播放器项应该异步缓冲,然后可以在队列中添加。
可以使用 [AVURLAsset loadValuesAsynchronouslyForKeys:completionHandler:]来完成
So in this case player item should be buffered asynchronously and after that it can be added in the queue.
It can be done using [AVURLAsset loadValuesAsynchronouslyForKeys: completionHandler:]
例如:
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:url options:nil];
NSArray *keys = [NSArray arrayWithObject:@"playable"];
[asset loadValuesAsynchronouslyForKeys:keys completionHandler:^()
{
dispatch_async(dispatch_get_main_queue(), ^
{
AVPlayerItem *playerItem = [[[AVPlayerItem alloc] initWithAsset:asset] autorelease];
[player insertItem:playerItem afterItem:nil];
});
}];
使用AVQueuePlayer的此解决方案队列可以填充没有任何间隙和冻结的项目。
Using this solution queue of AVQueuePlayer can be populated with items without any gaps and freezes.
这篇关于AVQueuePlayer无间隙播放和冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!