IOS7 视频播放 需要使用 MPMoviePlayerController
首先是加在一下库文件MediaPlayer.framework
然后实现如下的代码就好了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| #pragma mark - 视频播放 -(void) showMovie:(UIGestureRecognizer *)tap { NSLog(@"视频播放"); UIImageView * nanshanImage=[[UIImageView alloc]initWithFrame:CGRectMake(0,0,1024,699)]; nanshanImage.image=[UIImage imageNamed:@"boy.jpg"]; [self.view addSubview:nanshanImage]; UIButton* playButton= [[UIButton alloc]initWithFrame:CGRectMake(145, 250, 70, 80)]; [playButton addTarget:self action:@selector(PlayMovieAction:) forControlEvents:UIControlEventTouchUpInside]; playButton.backgroundColor=[UIColor redColor]; [self.view addSubview:playButton]; }
-(void)PlayMovieAction:(id)sender { NSString *path = [[NSBundle mainBundle] pathForResource:@"jinxiuMovie" ofType:@"mp4"]; NSURL *url = [NSURL fileURLWithPath:path]; MPMoviePlayerController *movie = [[MPMoviePlayerController alloc] initWithContentURL:url]; movie.controlStyle = MPMovieControlStyleFullscreen; [movie.view setFrame:self.view.bounds]; movie.initialPlaybackTime = -1; [self.view addSubview:movie.view]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMovieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:movie]; [movie play]; }
-(void)myMovieFinishedCallback:(NSNotification*)notify { MPMoviePlayerController* theMovie = [notify object]; [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:theMovie]; [theMovie.view removeFromSuperview];
NSLog(@"视频播放完成"); }
|
里面的播放文件是MP4格式的,格式支持:MOV、MP4、M4V、与3GP等格式,还支持多种音频格式。
刚开始接触先记录一下
参考文章:
http://www.oschina.net/question/213217\_40625