当前位置: 代码迷 >> Iphone >> iphone播发本地视频
  详细解决方案

iphone播发本地视频

热度:69   发布时间:2016-04-25 06:33:14.0
iphone播放本地视频

- (void)playPreviewVideo {
[UIApplication sharedApplication].statusBarHidden = YES;
NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"app" ofType:@"mp4"];
NSURL *url = [NSURL fileURLWithPath:urlStr];
if (!url) {
return;
}
MPMoviePlayerController *theMovie = [[MPMoviePlayerController alloc] init];
theMovie.view.backgroundColor = [UIColor blackColor];
theMovie.movieSourceType = MPMovieSourceTypeFile;
theMovie.scalingMode = MPMovieScalingModeAspectFill;
theMovie.controlStyle = MPMovieFinishReasonUserExited;
theMovie.view.frame = CGRectMake(0, 0, 480, 320);
[self.view addSubview:theMovie.view];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(myMovieFinishedCallback:)?
name:MPMoviePlayerPlaybackDidFinishNotification?
? object:theMovie];
[theMovie setContentURL:url];
[theMovie play];
}

- (void)myMovieFinishedCallback:(NSNotification *)aNotification {
MPMoviePlayerController *theMovie = [aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self?
name:MPMoviePlayerPlaybackDidFinishNotification?
?object:theMovie];
[theMovie.view removeFromSuperview];
[theMovie release];
theMovie = nil;
[UIApplication sharedApplication].statusBarHidden = YES;
}
  相关解决方案