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
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()
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With