Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVPlayer with Cloudflare

I am playing videos from url and it works well but now we are trying to switch to cloudflare and would need to handle the videos that are sent. The only problem now is every other video url works except a cloudflare url

how I am playing

let fileURL = URL(string: "https://watch.cloudflarestream.com/cb9618c34c4fbf6fa88bb48b73")
player = AVPlayer(URL: fileURL!)
playerLayer = AVPlayerLayer(player: player)
playerLayer!.frame = self.view.bounds
self.view.layer.addSublayer(playerLayer!)
player!.play()

how can I make AVPlayer play cloudflare videos

like image 493
King Avatar asked Apr 01 '26 03:04

King


1 Answers

I recommend using the m3u8 format and the full link will be like this https://videodelivery.net/5d5bc37ffcf54c9b82e996823bffbb81/manifest/video.m3u8 where 5d5bc37ffcf54c9b82e996823bffbb81 - VideoID. This ID I took from the browser source, but I can't play your example, perhaps you need to set some additional settings for your video to play. I mean videoID cb9618c34c4fbf6fa88bb48b73

You can test this code:

class ViewController: UIViewController {

    var player = AVPlayer()

    override func viewDidLoad() {
        super.viewDidLoad()


        let fileURL = URL(string: "https://videodelivery.net/5d5bc37ffcf54c9b82e996823bffbb81/manifest/video.m3u8")
        player = AVPlayer(url: fileURL!)
        let playerLayer = AVPlayerLayer(player: player)
        playerLayer.frame = self.view.bounds
        self.view.layer.addSublayer(playerLayer)
        player.play()
    }

}
like image 171
Vadim Nikolaev Avatar answered Apr 03 '26 16:04

Vadim Nikolaev