var url:NSURL! = NSURL(string: "http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8")
var playItem:AVPlayerItem! = AVPlayerItem(URL: url);
var player:AVPlayer! = AVPlayer(playerItem: playItem);
var playerLayer:AVPlayerLayer! = AVPlayerLayer(player: player);
self.view.layer.addSublayer(playerLayer);
player.play()
当我运行这些代码时,会有崩溃,有人能告诉我如何使用AVKit播放视频吗? Thx ^ ^
答案 0 :(得分:1)
试试这个:
//stream url
let movieUrl:NSURL? = NSURL (string: "http://YOUR URL")
if let url = movieUrl {
self.avPlayer = AVPlayer(URL: url)
self.avPlayerViewController.player = self.avPlayer
}
//Button action
@IBAction func live(sender: UIButton) {
self.presentViewController(self.avPlayerViewController, animated: true) { () -> Void in
self.avPlayerViewController.player?.play()
}