【问题标题】:IOS not playing urls from google cloud storageIOS 不播放来自谷歌云存储的网址
【发布时间】:2017-03-29 05:20:20
【问题描述】:

我将我的 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 的相同文件,它运行良好。以下是视频的示例公共 URL。

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

是否有任何标题问题或设备端是否存在问题。请帮忙。

【问题讨论】:

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


    【解决方案1】:

    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()
    }
    

    【讨论】:

    • 这会开始第一个 5 秒的视频,并且永远不会在此之前进行,您能帮忙吗?
    • 添加观察者到玩家项目: playerItem.addObserver(self, forKeyPath: "playbackBufferEmpty", options: .New, context: nil) playerItem.addObserver(self, forKeyPath: "playbackLikelyToKeepUp", options: .新的,上下文:nil) playerItem.addObserver(self,forKeyPath:“playbackBufferFull”,选项:.New,上下文:nil)
    • then 实现以下方法:覆盖 public func observeValueForKeyPath(keyPath: String?, ofObject object: AnyObject?, change: [String : AnyObject]?, context: UnsafeMutablePointer) { if object is AVPlayerItem { switch keyPath { case "playbackBufferEmpty": // player.play() case "playbackLikelyToKeepUp": // 隐藏加载器 // player.pause() case "playbackBufferFull": // 隐藏加载器 // player.pause() } } }
    猜你喜欢
    • 2012-01-24
    • 2012-12-09
    • 2013-01-29
    • 2018-12-24
    • 2014-07-25
    • 1970-01-01
    • 2020-09-10
    • 2015-07-03
    • 2016-10-12
    相关资源
    最近更新 更多