【问题标题】:AVPlayer in SwiftUISwiftUI 中的 AVPlayer
【发布时间】:2020-09-15 21:36:47
【问题描述】:

我对使用 swiftUI 还很陌生,我试图通过我自己的 vimeo 和 youtube 帐户在我的应用程序中播放视频,但我无法弄清楚,即使在互联网上搜索了几个小时之后。有没有解决的办法。我可以毫无问题地播放其他来源的 mp4 视频

struct player: UIViewControllerRepresentable {

    func makeUIViewController(context: UIViewControllerRepresentableContext<player>) -> AVPlayerViewController {

        let controller = AVPlayerViewController()
        let url = "https://vimeo.com/413494928"
        let player1 = AVPlayer(url: URL(string: url)!)
        controller.player = player1
        return controller
    }
    func updateUIViewController(_ uiViewController: AVPlayerViewController, context: UIViewControllerRepresentableContext<player>) {

    }
}

【问题讨论】:

    标签: youtube swiftui avplayer vimeo


    【解决方案1】:

    让它发挥作用

    func makeUIViewController(context: UIViewControllerRepresentableContext<player>) -> AVPlayerViewController {
    
        let controller = AVPlayerViewController()
        let url = "https://vimeo.com/413494928"
        let player1 = AVPlayer(url: URL(string: url)!)
        controller.player = player1
        player1.play()                 // << here !!
        return controller
    }
    

    【讨论】:

    • 谢谢您的回复。我现在有一个旋转的缓冲轮,但仍然没有视频
    猜你喜欢
    • 2021-08-30
    • 1970-01-01
    • 2021-03-24
    • 2020-08-10
    • 2020-03-05
    • 2020-06-14
    • 1970-01-01
    • 1970-01-01
    • 2021-12-22
    相关资源
    最近更新 更多