标签:
视频
1 // MARK: - 播放视频 2 /*----- 播放视频 ------*/ 3 4 5 func moviePlayerPreloadFinish(notification:NSNotification) 6 { 7 println("播放完毕") 8 } 9 10 //声明一个媒体播放器 11 var moviePlayer:MPMoviePlayerController? 12 13 @IBAction func playMV() 14 { 15 let filePath:String? = NSBundle.mainBundle().pathForResource("namingRule", ofType: "mp4") 16 17 //本地文件,使用fileURLWithPath来声明NSURL对象 18 moviePlayer = MPMoviePlayerController(contentURL: NSURL(fileURLWithPath: filePath!)) 19 20 //如果播放网上视频,需要通过string方法来声明NSURL对象 21 // moviePlayer = MPMoviePlayerController(contentURL: NSURL(string: "视频网址")) 22 23 //用MPMoviePlayerController做在线音乐播放 24 // moviePlayer = MPMoviePlayerController(contentURL: NSURL(string: "http://202.204.208.83/gangqin/download/music/02/03/02/Track08.mp3")) 25 26 moviePlayer!.view.frame = self.view.frame; 27 28 29 //设置播放器样式 30 moviePlayer!.controlStyle = MPMovieControlStyle.Fullscreen 31 self.view.addSubview(moviePlayer!.view) 32 moviePlayer!.play() 33 34 //需要使用 NSNotificationCenter 类,为电影播放器添加一个观察者(observer): 35 36 var notificationCenter: Void = NSNotificationCenter.defaultCenter().addObserver(self, selector: "moviePlayerPreloadFinish:", name: MPMoviePlayerPlaybackDidFinishNotification, object: nil) 37 } 38 /*----- 播放视频 ------*/ 39
标签:
原文地址:http://www.cnblogs.com/iCocos/p/4559318.html