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

猜你喜欢

转载自374016526.iteye.com/blog/1172633
今日推荐