iPhone 视频播放

theMovie = [[MPMoviePlayerController alloc] init];

theMovie.view.backgroundColor = [UIColor blackColor];

theMovie.view.frame = [AppUIViewController getInstance].view.bounds;

UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, theMovie.view.center.y - 25, 

  theMovie.view.frame.size.width, 50)];

label.text = @"正在连接视频数据...";

label.textAlignment = UITextAlignmentCenter;

label.backgroundColor = [UIColor clearColor];

label.textColor = [UIColor whiteColor];

[theMovie.view addSubview:label];

[theMovie.view sendSubviewToBack:label];

[label release];

[[AppUIViewController getInstance].view addSubview:theMovie.view];

theMovie.movieSourceType = MPMovieSourceTypeFile;

theMovie.scalingMode = MPMovieScalingModeAspectFill;

theMovie.controlStyle = MPMovieFinishReasonUserExited;

[[NSNotificationCenter defaultCenter] addObserver:self

selector:@selector(myMovieFinishedCallback:) 

name:MPMoviePlayerPlaybackDidFinishNotification 

  object:theMovie];

[theMovie setContentURL:url];

[theMovie play];

- (void)myMovieFinishedCallback:(NSNotification *)aNotification 
{
float curPlaybackTime = theMovie.currentPlaybackTime;
int playstate = theMovie.playbackState;
//int duration = theMovie.duration;
[[NSNotificationCenter defaultCenter] removeObserver:self 
name:MPMoviePlayerPlaybackDidFinishNotification 
 object:theMovie];
[theMovie.view removeFromSuperview];
[theMovie release];
theMovie = nil;
[UIApplication sharedApplication].statusBarHidden = YES;
if ((curPlaybackTime >= 0
 && (playstate == MPMoviePlaybackStatePlaying))) { //自己播放停止
}

猜你喜欢

转载自374016526.iteye.com/blog/1156916