带有 Cloudflare 的 AVPlayer
AVPlayer with Cloudflare
我正在播放来自 url 的视频并且效果很好,但现在我们正在尝试切换到 cloudflare,并且需要处理发送的视频。现在唯一的问题是除了 cloudflare url
之外的所有其他视频 url 都能正常工作
我玩的怎么样
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()
如何让 AVPlayer 播放 cloudflare 视频
我推荐使用m3u8
格式,完整的link是这样的
https://videodelivery.net/5d5bc37ffcf54c9b82e996823bffbb81/manifest/video.m3u8 where 5d5bc37ffcf54c9b82e996823bffbb81 - VideoID. This ID I took from the browser source,但我无法播放您的示例,也许您需要设置一些额外的设置才能播放您的视频。我是说 videoID cb9618c34c4fbf6fa88bb48b73
您可以测试这段代码:
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()
}
}
我正在播放来自 url 的视频并且效果很好,但现在我们正在尝试切换到 cloudflare,并且需要处理发送的视频。现在唯一的问题是除了 cloudflare url
之外的所有其他视频 url 都能正常工作我玩的怎么样
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()
如何让 AVPlayer 播放 cloudflare 视频
我推荐使用m3u8
格式,完整的link是这样的
https://videodelivery.net/5d5bc37ffcf54c9b82e996823bffbb81/manifest/video.m3u8 where 5d5bc37ffcf54c9b82e996823bffbb81 - VideoID. This ID I took from the browser source,但我无法播放您的示例,也许您需要设置一些额外的设置才能播放您的视频。我是说 videoID cb9618c34c4fbf6fa88bb48b73
您可以测试这段代码:
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()
}
}