带有Cloudflare的AVPlayer

问题描述 投票:0回答:1

我正在播放来自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视频

swift avplayer cloudflare
1个回答
0
投票

我建议使用m3u8格式,完整链接将如下所示https://videodelivery.net/5d5bc37ffcf54c9b82e996823bffbb81/manifest/video.m3u8其中5d5bc37ffcf54c9b82e996823bffbb81-视频ID。我使用了from the browser source这个ID,但我无法播放您的示例,也许您需要为视频播放设置一些其他设置。我的意思是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()
    }

}
© www.soinside.com 2019 - 2024. All rights reserved.