swift AVPlayer 播放视频时报错

ios9.0之后,使用AVPlayerViewController播放视频


importUIKit

importAVKit

importAVFoundation

classDetailViewController:UIViewController{

/*

2016-05-11 AVPlayerViewController实现视频播放

*/

varplayerVC:AVPlayerViewController?

//设置一个变量,


overridefuncviewDidLoad() {

super.viewDidLoad()

// 2016-05-11 AVPlayerViewController

playerVC=AVPlayerViewController()

// 0.获取视频的播放地址

leturl =NSURL(string:"http://v1.mukewang.com/57de8272-38a2-4cae-b734-ac55ab528aa8/L.mp4")

letplayer =AVPlayer(URL: url!)

playerVC?.player= player

//self.addChildViewController(playerVC!)

self.view.addSubview((playerVC?.view)!)

playerVC?.view.frame=self.view.frame

player.play()

}

// 2016-05-11 AVPlayerViewController

overridefunctouchesBegan(touches:Set, withEvent event:UIEvent?) {

if(presentedViewController!=nil) {

return

}

presentViewController(playerVC!, animated:true) { () ->Voidin

self.playerVC?.player?.play()

}

}

overridefuncdidReceiveMemoryWarning() {

super.didReceiveMemoryWarning()

// Dispose of any resources that can be recreated.

}

}

但是会出现下列错误


解决办法:在mac mini下插上耳机。只可惜我的是黑苹果,不知道有没有解决方案。

你可能感兴趣的:(swift AVPlayer 播放视频时报错)