ios开发——实用技术篇Swift篇&视频

视频

 // MARK: - 播放视频
     /*----- 播放视频 ------*/

     func moviePlayerPreloadFinish(notification:NSNotification)
     {
         println("播放完毕")
     }

     //声明一个媒体播放器
     var moviePlayer:MPMoviePlayerController?

     @IBAction func playMV()
     {
         let filePath:String? = NSBundle.mainBundle().pathForResource("namingRule", ofType: "mp4")

         //本地文件,使用fileURLWithPath来声明NSURL对象
         moviePlayer = MPMoviePlayerController(contentURL: NSURL(fileURLWithPath: filePath!))

         //如果播放网上视频,需要通过string方法来声明NSURL对象
 //        moviePlayer = MPMoviePlayerController(contentURL: NSURL(string: "视频网址"))

         //用MPMoviePlayerController做在线音乐播放
 //        moviePlayer = MPMoviePlayerController(contentURL: NSURL(string: "http://202.204.208.83/gangqin/download/music/02/03/02/Track08.mp3"))

         moviePlayer!.view.frame = self.view.frame;

         //设置播放器样式
         moviePlayer!.controlStyle = MPMovieControlStyle.Fullscreen
         self.view.addSubview(moviePlayer!.view)
         moviePlayer!.play()

         //需要使用 NSNotificationCenter 类,为电影播放器添加一个观察者(observer):

         var notificationCenter: Void = NSNotificationCenter.defaultCenter().addObserver(self, selector: "moviePlayerPreloadFinish:", name: MPMoviePlayerPlaybackDidFinishNotification, object: nil)
     }
     /*----- 播放视频 ------*/
     
 
上一篇:移动端1px问题


下一篇:poj 2488 A Knight's Journey( dfs )