How to detect AVPlayer actually started to play in swift

后端 未结 7 1463
情话喂你
情话喂你 2020-12-16 10:59

Hello I have set my UISliderminimum value to 0.00. Then I set it\'s max value in this way.

self.viewPlayer.layer.addSublayer(playerLayer)
    le         


        
相关标签:
7条回答
  • 2020-12-16 11:35

    Here is what I did to actually know when video started (not when it's only ready to start).

    Swift 4

    player = AVPlayer(url: URL(fileURLWithPath: path))
    player.addObserver(self, forKeyPath: "rate", options: NSKeyValueObservingOptions.new, context: nil)
    
    override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
        if keyPath == "rate" {
            if player.rate > 0 {
                print("video started")
            }
        }
    }
    
    0 讨论(0)
提交回复
热议问题