swift2 如何在Swift 2中使用AVPLayer播放来自远程URL的视频

cnh2zyt3  于 2022-11-06  发布在  Swift
关注(0)|答案(1)|浏览(201)

我尝试使用AVPlayer的视频文件,我上传了一些视频在一个公共文件夹中的googleDrive,dropbox,riouxsvn和github...他们都不能播放。
否则,我找到了工作的样本,我注意到工作的视频是那些可以在浏览器中自动播放的视频。
播放器不是真实的的问题...这个问题更多的是与视频有关。如果我点击任何一个可以播放的网址,视频会立即在浏览器中开始播放...如果我点击不能播放的网址,你会看到视频没有开始播放,我必须点击它才能播放(Dropbox和谷歌驱动器),或者在riouxsvn中视频开始下载。
所以我不知道,我也不能在互联网上找到如何解决这个问题。你有什么想法,我应该如何以及在哪里上传视频,以便它可以在设备上播放?

@IBAction func playVideoTest(sender: AnyObject) {

    //Video URLs that can be played
    //let url:NSURL = NSURL(string: "http://jplayer.org/video/m4v/Big_Buck_Bunny_Trailer.m4v")!
    //let url:NSURL = NSURL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")!

    //Video URLs that can NOT be played
    let url:NSURL = NSURL(string: "https://svn.riouxsvn.com/salsa4allmedia/Videos/SampleVideo.mp4")!
    //let url:NSURL = NSURL(string: "https://www.dropbox.com/s/kkjwajuo7r1mqox/SampleVideo.mp4?dl=0")!
    //let url:NSURL = NSURL(string: "https://drive.google.com/open?id=0B1tAk1RMaHu0T1dVNWFYS1ExS0k")!
    //let url:NSURL = NSURL(string: "https://github.com/dervatii/SalsaMedia/blob/master/SampleVideo.MOV")!

    var player = AVPlayer()

    player = AVPlayer(URL: url)
    let playerController = AVPlayerViewController()
    playerController.player = player

    self.presentViewController(playerController, animated: true) {
        player.play()
    }
}

Check the result showed in the simulator here

zengzsys

zengzsys1#

快3

@IBAction func playVideo(_ sender: AnyObject) {

                let videoURL = NSURL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4")
                let player = AVPlayer(url: videoURL! as URL)
                let playerLayer = AVPlayerLayer(player: player)
                playerLayer.frame = vedioPlayer.bounds
                vedioPlayer.layer.addSublayer(playerLayer)
                player.play()
}

相关问题