1

在播放选择器控制器中挑选的视频文件时遇到问题,上传到服务器。“ https://starfish.chat/attachment/112/253.mov

然后只需下载视频并添加到项目中。它播放。

AVPlayerViewController新调用的委托方法。

控制器看起来像这样: 在此处输入图像描述

if let playerController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("player_controller_id") as? AVPlayerViewController {

    do {
        try AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayback)
        try AVAudioSession.sharedInstance().setActive(true)

        let s = "https://starfish.chat/attachment/112/253.mov"
        let url2 = NSURL(string: s)

        let p = NSBundle.mainBundle().pathForResource("253", ofType: "mov")
        let url3 = NSURL(fileURLWithPath: p!)

        let playerItem = AVPlayerItem(URL: url2!)
        NSNotificationCenter.defaultCenter().addObserverForName(nil, object: playerItem, queue: nil, usingBlock: { (notification) -> Void in
                            print("ERROR: " + (playerItem.error?.description ?? "") + "\n")
                            print("LOG: " + (playerItem.errorLog()?.debugDescription ?? "") + "\n")
                            print("ACCESS: " + (playerItem.accessLog()?.debugDescription ?? "") + "\n")
                        })

        let player = AVPlayer(playerItem: playerItem)

        playerController.player = player

        if #available(iOS 9, *) {
            playerController.delegate = self
        }

        self.presentViewController(playerController, animated: true, completion: { () -> Void in

                        })
    } catch {}
}

日志:

ERROR: 

LOG: <AVPlayerItemErrorLog: 0x15dbd0ef0>
#Version: 1.0
#Software: AppleCoreMedia/1.0.0.13D15 (iPhone; U; CPU OS 9_2_1 like Mac OS X; uk_ua)
#Date: 2016/02/17 18:08:02.002

ACCESS: <AVPlayerItemAccessLog: 0x15db5a970>
#Version: 1.0
#Software: AppleCoreMedia/1.0.0.13D15 (iPhone; U; CPU OS 9_2_1 like Mac OS X; uk_ua)
#Date: 2016/02/17 18:08:02.002

ERROR: 

LOG: <AVPlayerItemErrorLog: 0x15daa3380>
#Version: 1.0
#Software: AppleCoreMedia/1.0.0.13D15 (iPhone; U; CPU OS 9_2_1 like Mac OS X; uk_ua)
#Date: 2016/02/17 18:08:02.002

ACCESS: <AVPlayerItemAccessLog: 0x15daa93f0>
#Version: 1.0
#Software: AppleCoreMedia/1.0.0.13D15 (iPhone; U; CPU OS 9_2_1 like Mac OS X; uk_ua)
#Date: 2016/02/17 18:08:02.002
4

0 回答 0