AVPlayer缓冲,暂停通知和海报框架 [英] AVPlayer buffering, pausing notification, and poster frame
问题描述
我有一些与 AVPlayer
相关的问题:
I have some questions related to AVPlayer
which are:
-
当我们暂停
AVPlayer
通过[播放器暂停]
时,AVPlayer
继续缓冲来自网络的视频还是只是停止?我无法在apple的文档中获得与此相关的任何信息。此外,是否可以强制AVPlayer在暂停时保持缓冲,这样如果我们暂停的视频正在等待第一个视频结束,那么我们不会发现视频之间有任何差距?
When we pause the
AVPlayer
through[player pause]
does theAVPlayer
keep buffering the video from the network or does it just stop? I couldn't get any info related to this in apple's documentation. Also, is it possible to force the AVPlayer to keep buffering while in pause, so that if we have the paused video is in waiting for the first video to be ended then we wouldn't find any gap in between the videos?
暂停 AVPlayer
我们可以在 [播放器暂停]上发生任何事件
。
我们可以在 AVPlayer
上显示静止图片几秒钟吗?
Can we show still image on AVPlayer
for some seconds?
谢谢
推荐答案
1) AVPlayer
将在几种情况下缓冲视频,没有一个清晰的记录。我说你在初始化视频时以及当你替换当前项目时可以期待缓冲。
你可以观察 currentItem.loadedTimeRanges
来了解发生了什么。该属性将告诉您已加载了哪些视频时间范围。
1) AVPlayer
will buffer the video in several cases, none cleary documented. I'd say you can expect buffering when you init the video, and when you replace the current item.
You can observe currentItem.loadedTimeRanges
to know what's going on. That property will tell you which video time ranges has been loaded.
此外,还有一些其他 currentItem
属性这可能对你有帮助: playbackLikelyToKeepUp
, playbackBufferFull
和 playbackBufferEmpty
。
Also, there is a few other currentItem
properties that may help you: playbackLikelyToKeepUp
, playbackBufferFull
and playbackBufferEmpty
.
实现完美的无间隙播放并不容易。
Achieving a perfect gapless playback is not easy.
/* player is an instance of AVPlayer */
[player addObserver:self
forKeyPath:@"currentItem.loadedTimeRanges"
options:NSKeyValueObservingOptionNew
context:kTimeRangesKVO];
在 observeValueForKeyPath:ofObject:change:context:
:
if (kTimeRangesKVO == context) {
NSArray *timeRanges = (NSArray *)[change objectForKey:NSKeyValueChangeNewKey];
if (timeRanges && [timeRanges count]) {
CMTimeRange timerange = [[timeRanges objectAtIndex:0] CMTimeRangeValue];
NSLog(@" . . . %.5f -> %.5f", CMTimeGetSeconds(timerange.start), CMTimeGetSeconds(CMTimeAdd(timerange.start, timerange.duration)));
}
}
2)只要留意 player.rate
。
[player addObserver:self
forKeyPath:@"rate"
options:NSKeyValueObservingOptionNew
context:kRateDidChangeKVO];
然后在你的 observeValueForKeyPath:ofObject:change:context:
:
if (kRateDidChangeKVO == context) {
NSLog(@"Player playback rate changed: %.5f", player.rate);
if (player.rate == 0.0) {
NSLog(@" . . . PAUSED (or just started)");
}
}
3)你可以使用静止图像制作给定长度的电影但更容易使用播放器顶部的常规 UIImageView
。需要时隐藏/显示它。
3) You can build a movie of a given length using a still image but it's easier to use a regular UIImageView
on top of the player. Hide/show it when needed.
示例项目:随时玩我写的代码是为了支持我的回答。
这篇关于AVPlayer缓冲,暂停通知和海报框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!