//建立播放器並播放視頻。-(void) playMovie{ NSString* videoPath = [[Globals getResourceManager] loadVideo:@"abcSong"]; player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:videoPath]]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:player]; player.controlStyle = MPMovieControlStyleFullscreen; player.view.frame = [Globals getScreenRect]; player.initialPlaybackTime = -1; [self.view addSubview:player.view]; player.backgroundColor = [UIColor blackColor]; player.useApplicationAudioSession = NO; player.movieControlMode = MPMovieControlModeHidden; player.scalingMode = MPMovieScalingModeAspectFit; [player play];
//當視頻播放結束釋放資源。-(void) movieFinishedCallback:(NSNotification*) aNotification{ [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player]; [player stop]; [player.view removeFromSuperview]; [player release]; player = nil;}