AVPlayer没有显示启动微调器

时间:2015-11-11 14:20:46

标签: swift avplayer tvos avplayerviewcontroller

我正在尝试在我的应用程序中播放tvOS上的远程mp4视频。有一个小问题,当我设置AVPlayerViewController.view.frame = self.view.frame时,在视频加载之前,微调器就不会出现。但是,如果我设置AVPlayerViewController.view.frame = CGRectMake(0.0, 0.0, 1920.0, 1079.0)它完全正常。微调器在开始时加载,然后出现视频。

import UIKit
import AVKit

class PlayViewController : UIViewController {

    var avplayerVC : AVPlayerViewController?
    var videoUrlStr : String?

    override func viewDidLoad() {
        super.viewDidLoad()

        print("In PlayViewController View Did Load")

        avplayerVC = AVPlayerViewController()

        let avAsset = AVAsset(URL: NSURL.init(string: videoUrlStr!)!)
        let avPlayerItem = AVPlayerItem(asset: avAsset)
        avplayerVC?.player = AVPlayer(playerItem: avPlayerItem)

        avplayerVC?.player?.seekToTime(kCMTimeZero)

        avplayerVC?.player?.addObserver(self, forKeyPath: "status", options: .New, context: nil)

        avplayerVC?.player?.play()
        print("Status 1: " +  "\(avplayerVC?.player?.status.rawValue)")

        print(self.view?.frame)

        // doesn't work
        //avplayerVC?.view.frame =  self.view.frame

        // doesn't work
        //avplayerVC?.view.frame =  CGRectMake(0.0, 0.0, 1920.0, 1080.0)

        // works fine
        avplayerVC?.view.frame =  CGRectMake(0.0, 0.0, 1920.0, 1079.0)
        self.view.addSubview((avplayerVC?.view!)!)
    }
}

我还尝试在print(self.view?.frame)中添加viewDidLoad的日志,然后打印出(0.0 0.0; 1920.0,1080.0)

0 个答案:

没有答案