您好我已将我的UiSliderminimum值设置为0.00.然后我以这种方式设置它的最大值.
self.viewPlayer.layer.addSublayer(playerLayer) let duration : CMTime = avPlayer.avPlayer.currentItem!.asset.duration let seconds : Float64 = CMTimeGetSeconds(duration) sliderBar.maximumValue=Float(seconds) sliderBar!.isContinuous = false sliderBar!.tintColor = UIColor.green
但我得到了这个例外
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException',reason: 'Attempting to set a slider's minimumValue (0.000000) to be larger than the maximumValue (nan)' enter code here
我知道在prepareForPlay()实际播放后,真正播放视频需要一些时间.那么如何才能检测到播放器何时真正开始播放视频?
请帮我.
谢谢
解决方法
您可以像这样在AVPlayer的对象上添加观察者
player.addObserver(self,forKeyPath: "status",options: NSKeyValueObservingOptions.new,context: nil)
你可以像这样检查AVPlayer的状态变化
func observeValueForKeyPath(keyPath: String?,ofObject object: AnyObject?,change: [String : AnyObject]?,context: UnsafeMutableRawPointer) { if keyPath == "status" { print(player.status) } }