ios9.0之后排监,使用AVPlayerViewController播放視頻
importUIKit
importAVKit
importAVFoundation
classDetailViewController:UIViewController{
/*
2016-05-11 AVPlayerViewController實(shí)現(xiàn)視頻播放
*/
varplayerVC:AVPlayerViewController?
//設(shè)置一個(gè)變量,
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.
}
}
但是會(huì)出現(xiàn)下列錯(cuò)誤
解決辦法:在mac mini下插上耳機(jī)蹲姐。只可惜我的是黑蘋果魏蔗,不知道有沒有解決方案劝堪。