gpt4 book ai didi

ios - 从数据 block 播放视频

转载 作者:行者123 更新时间:2023-11-30 12:36:27 25 4
gpt4 key购买 nike

我从节点服务器接收到了数据 block 中的视频。但视频无法在 AVPlayer 中播放。这是我的代码。

           let videoUrl = http://staging.teemo.me/api/video/stream/sample12.MOV

playVideo(path:videoUrl, self)

func playVideo(path:String, controller:UIViewController){
let yourFinalVideoURL = path
try! AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback, with: [])
if (yourFinalVideoURL != "") {
let player = AVPlayer(url: NSURL(fileURLWithPath: yourFinalVideoURL) as URL)
let playerController = AVPlayerViewController()
playerController.player = player
controller.present(playerController, animated: true) {
//player.play()
if #available(iOS 10.0, *) {
player.playImmediately(atRate: 1.0)
} else {
player.play()
}
}
}
}

最佳答案

以下代码对我有用:

let videoURL = URL(string: "Some url")
let player = AVPlayer(url: videoURL!)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
self.present(playerViewController, animated: true) {
playerViewController.player!.play()
}

但是,当我尝试使用您的网址时,它不起作用。我在 .plist 中添加了 NSAppTransportSecurity,但它也不起作用。很明显是你的url有问题,尝试将文件sample12.MOV的扩展名改为sample12.mp4

关于ios - 从数据 block 播放视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42807176/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com