E
E
Evgeny Konkin2017-06-01 20:22:29
iOS
Evgeny Konkin, 2017-06-01 20:22:29

Restore Stream AVPlayer on error?

Hey!
I'm making an IPTV player, it's simple!

var player: AVPlayer?

func setupPlayerView(_ urlString: String) {
        
        if let url = URL(string: urlString) {
            player = AVPlayer(url: url)
            let playerLayer = AVPlayerLayer(player: player)
            self.layer.addSublayer(playerLayer)
            playerLayer.frame = self.frame
            player?.play()
        }
    }

Everything works fine, but when there are failures in the stream or how to do it right? how to "catch" this moment so that the application does not crash and resume the stream?
Please tell me or throw some link in this direction!
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Gorb, 2017-06-06
@konnn

1. Add an observer in viewDidLoad
2. Check status

// catch changes to status
    override func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
        if keyPath == "status" {
            // do something
        }
    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question