视屏播放

  1. -(void)playMovie:(NSString *)fileName{  
  2.     //视频文件路径  
  3.     NSString *path = [[NSBundle mainBundle] pathForResource:fileName ofType:@"mp4"];  
  4.     //视频URL  
  5.     NSURL *url = [NSURL fileURLWithPath:path];  
  6.     //视频播放对象  
  7.     MPMoviePlayerController *movie = [[MPMoviePlayerController alloc] initWithContentURL:url];  
  8.     movie.controlStyle = MPMovieControlStyleFullscreen;  
  9.     [movie.view setFrame:self.view.bounds];  
  10.     movie.initialPlaybackTime = -1;  
  11.     [self.view addSubview:movie.view];  
  12.     // 注册一个播放结束的通知  
  13.     [[NSNotificationCenter defaultCenter] addObserver:self  
  14.                                              selector:@selector(myMovieFinishedCallback:)  
  15.                                                  name:MPMoviePlayerPlaybackDidFinishNotification  
  16.                                                object:movie];  
  17.     [movie play];  
  18. }  
  19.   
  20. #pragma mark -------------------视频播放结束委托--------------------  
  21.   
  22. /* 
  23.  @method 当视频播放完毕释放对象  
  24.  */  
  25. -(void)myMovieFinishedCallback:(NSNotification*)notify  
  26. {  
  27.     //视频播放对象  
  28.     MPMoviePlayerController* theMovie = [notify object];  
  29.     //销毁播放通知  
  30.     [[NSNotificationCenter defaultCenter] removeObserver:self  
  31.                                                     name:MPMoviePlayerPlaybackDidFinishNotification  
  32.                                                   object:theMovie];  
  33.     [theMovie.view removeFromSuperview];  
  34.     // 释放视频对象  
  35.     [theMovie release];  
  36. }
posted @ 2015-11-16 21:09  赵小磊2015  阅读(79)  评论(0)    收藏  举报