AVPlayer 缓冲语句
我正在使用 AVPlayer 播放来自互联网的实时流,并且需要显示播放器正在缓冲的情况:
我正在使用 NStimer:
timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:@selector(buffering) userInfo:nil repeats:YES];
-(void)buffering {
if(radiosound.rate == 1.0)
[activityIndicator stopAnimating];
else
[activityIndicator startAnimating];
}
当然,速率属性无法正常显示! 是否还有其他语句可以了解 AVPlayer 是否正在缓冲?
I am using the AVPlayer to play a live stream from the Internet, and need to show than the player is buffering :
I am using an NStimer :
timer = [NSTimer scheduledTimerWithTimeInterval:(1.0/2.0) target:self selector:@selector(buffering) userInfo:nil repeats:YES];
-(void)buffering {
if(radiosound.rate == 1.0)
[activityIndicator stopAnimating];
else
[activityIndicator startAnimating];
}
For sure rate property is not working properly to show !
Is it an other statement to know if the AVPlayer is buffering ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要考虑为加载时间设置键值观察器,并使用它来确定您是否在当前播放点等待数据。
观察者是在
AVPlayerItem
上使用addObserver:self forKeyPath: options: context:
方法设置的,然后在observeValueForKeyPath: ofObject:change: context:
回调中设置的您可以通过与播放器正在播放的项目中的位置进行比较来计算出已加载的时间。缓冲时您不会看到
rate
变量降至零,因为这是所需的播放速率,而不是实际达到的速率。You need to look at setting up key-value observers for the loaded times, and use that to figure out if you are waiting for data at the current play point.
Observers are setup using
addObserver:self forKeyPath: options: context:
method onAVPlayerItem
and then in theobserveValueForKeyPath: ofObject: change: context:
callback you can figure out what times have been loaded compared with where in the item the player is playing.You won't see the
rate
variable drop to zero when buffering, as this is the desired playback rate, not the actual rate being achieved.将 NSURLConnection 类与 NSURLConnectionDataDelegate 协议结合使用。
Use the NSURLConnection class in conjunction with the NSURLConnectionDataDelegate protocol.