分享

iOS视频播放代码

 没原创_去搜索 2016-01-19
http://blog.csdn.net/yhawaii/article/details/7601209


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

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章