AVPlayerViewController在iOS8中工作,但在IOS7中不工作

时间:2015-04-06 22:38:26

标签: swift ios7 ios8

我一直试图让它工作一段时间,我似乎无法弄清问题是什么。这段代码在IOS8上工作正常但在IOS7中我收到错误。当我按照调试导航器时,我可以看到此错误。 在调试区域中,我只得到(lldb)错误

Thread 1: EXC_BAD_ACCESS (code=1, address=0x10)

这是我(在IOS8上)的videoViewController工作代码

import UIKit
import AVKit
import AVFoundation
import MediaPlayer

class VideoVC: UIViewController {
override func viewDidLoad() {
    super.viewDidLoad()

    var url:NSURL = NSURL(string: "http://jplayer.org/video/m4v/Big_Buck_Bunny_Trailer.m4v")!
    let player = AVPlayer(URL: url)
    let playerController = AVPlayerViewController()

    playerController.player = player
    self.addChildViewController(playerController)
    self.view.addSubview(playerController.view)
    playerController.view.frame = self.view.frame

    player.play()
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
}

1 个答案:

答案 0 :(得分:2)

AVPlayerViewController已作为AVKit的一部分在iOS8中引入。如果您需要支持早期的iOS版本,则需要使用MPMediaPlayerViewController。

它在AVPlayerViewController文档页面的文档 - 通知可用性部分中公开: https://developer.apple.com/library/ios/documentation/AVFoundation/Reference/AVPlayerViewController_Class/

如果您对媒体播放感到好奇,请观看WWDC 2014 Session 513: http://devstreaming.apple.com/videos/wwdc/2014/503xx50xm4n63qe/503/503_hd_mastering_modern_media_playback.mov?dl=1