视屏播放

  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. }

转载于:https://www.cnblogs.com/zhaoxiaolei2015/p/4970073.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值