AVPlayer,播放/暂停状态的通知? [英] AVPlayer, notification for play/pause state?
问题描述
我正在寻找一种方法来获知 AVPlayer
开始播放的确切时刻。有费率属性,但目前我正在用 NSTimer
定期检查以获取更新。
I'm searching for a way to get notified the exact moment when AVPlayer
starts playing. There's the "rate" property, but currently I am checking it periodically with an NSTimer
to get updates.
I尝试了KVO,但显然它不符合KVO。
I tried KVO, but apparently it's not KVO compliant.
我知道有事件 -的-avplayer状态>截至。但是我在这里谈论暂停。
I know that there are events when the player ENDED. But i'm talking about pause here.
我也KVO订阅了 AVPlayerItem的
状态,但它正在显示我在HTTP资产完成缓存时,没有播放/暂停。我也开始收集播放/暂停的所有调用,之后请求即时UI更新,但在 AVPlayer
真正开始播放之前需要更多的runloops。我只是喜欢立即更新我的按钮 。
I also KVO subscribed to AVPlayerItem's
"status", but it's showing me when the HTTP asset has finished caching, no play/pause. I also started collecting all calls of play/pause, requesting an instant UI update afterwards, but it takes some more runloops before AVPlayer
really starts playing. I'd just love to update my button instantly.
推荐答案
对于i OS 10 以后您可以检查AVPlayer的新属性 timeControlStatus 。
For iOS 10 onwards You can check new property of AVPlayer timeControlStatus.
if(avplayerObject.timeControlStatus == AVPlayerTimeControlStatusPaused)
{
//Paused mode
}
else if(aavplayerObject.timeControlStatus==AVPlayerTimeControlStatusPlaying)
{
//Play mode
}
这篇关于AVPlayer,播放/暂停状态的通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!