我正在将我的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中的相同文件,它运行正常。以下是视频的示例公共网址。
是否存在标题问题或设备端存在问题?请帮忙。
答案 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()
}