iPadでMPMoviePlayerControllerを使う
iPadでムービーを再生するにはMPMoviePlayerControllerを使いますが
今までとは少し使い方が変わっています。
OS 3.2のiPadでムービーを再生する場合は、こんな感じです。
NSBundle* bundle=[NSBundle mainBundle]; NSString* path=[bundle pathForResource:@"DEMO" ofType:@"m4v"]; NSURL* url=[NSURL fileURLWithPath:path]; MPMoviePlayerController *movie=[[MPMoviePlayerController alloc] initWithContentURL:url]; movie.scalingMode=MPMovieScalingModeAspectFit; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:movie]; [movie prepareToPlay]; [movie play]; [movie.view setFrame:CGRectMake(39, 53, 960 , 540)]; movie.view.backgroundColor = [UIColor clearColor]; [self.view addSubview:movie.view];
-(void)movieFinishedCallback:(NSNotification*)notification { MPMoviePlayerController* movie = [notification object]; [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:movie]; [movie release]; }