IOS没有从谷歌云存储中播放网址

时间:2016-11-15 10:50:29

标签: ios video media-player google-cloud-storage mpmovieplayercontroller

我正在将我的MP4视频存储在谷歌云端存储中并尝试使用MPMoviePlayerController在iOS设备中播放它们但它没有播放。但是,如果我将Dropbox上的相同文件上传到公共,它就可以正常播放。

    let videoURLWithPath = "https://storage.googleapis.com/pioctave/577265bce6058511008a39dd/57bc34d5683eb51100173a46-video/pioctave.mp4"
    print(videoURLWithPath)
    let videoURL = NSURL(string: videoURLWithPath)


    moviePlayer = MPMoviePlayerController(contentURL: videoURL)
    moviePlayer.view.frame = CGRectMake(0.0, 0.0, self.view.frame.size.width, self.header_video_img!.frame.size.height)

    self.view.addSubview(moviePlayer.view)
    moviePlayer.fullscreen = false
    moviePlayer.shouldAutoplay = true

    moviePlayer.controlStyle = MPMovieControlStyle.Fullscreen
    moviePlayer.scalingMode = MPMovieScalingMode.AspectFill

    moviePlayer.play()

我在Android中使用了GCS中的相同文件,它运行正常。以下是视频的示例公共网址。

https://storage.googleapis.com/pioctave/577265bce6058511008a39dd/57bc34d5683eb51100173a46-video/pioctave.mp4

是否存在标题问题或设备端存在问题?请帮忙。

1 个答案:

答案 0 :(得分:0)

不推荐使用MPMoviePlayerController。使用AVPlayerViewController而不是MPMoviePlayerController。

以下是代码:

let videoURL = NSURL(string: "https://storage.googleapis.com/pioctave/577265bce6058511008a39dd/57bc34d5683eb51100173a46-video/pioctave.mp4")
let player = AVPlayer(url: videoURL! as URL)
let playerViewController = AVPlayerViewController()
playerViewController.player = player
self.present(playerViewController, animated: true) {
    playerViewController.player!.play()
}