iOS 3.1.3 까지는 동영상 재생을 원할때 MPMoviePlayerController를 사용했었습니다.
iOS 3.2 이상 버전에서는 MPMoviePlayerViewController가 추가되었습니다.

아래와 같이 사용하면 3.1.3 이전 버전과 3.2 이상 버전에서 모두 동작하도록 할 수 있습니다.
제 경우에는 UIViewController에 아래 코드를 추가하고 동영상 재생을 원하는 곳에서 노티피케이션으로 알려서 재생을 하는 방식으로 처리했습니다.


- (void) moviePlayBack:(NSNotification *)noti {

NSURL *movieURL = (NSURL *)[[noti userInfo] objectForKey:@"url"];

if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 3.2) {

MPMoviePlayerViewController *playerView = [[MPMoviePlayerViewController alloc] initWithContentURL:movieURL];

playerView.view.backgroundColor = [UIColor blackColor];

playerView.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:playerView.moviePlayer];

[self presentMoviePlayerViewControllerAnimated:playerView];

[playerView release];

} else if ([[[UIDevice currentDevice] systemVersion] doubleValue] < 3.2) {

MPMoviePlayerController* moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

moviePlayer.scalingMode = MPMovieScalingModeAspectFit;

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playbackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];

[moviePlayer play];

}

}


- (void) playbackDidFinish:(NSNotification *)noti {

if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 3.2) {

    MPMoviePlayerController *player = [noti object];

    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player];

    [player stop];

    [self dismissMoviePlayerViewControllerAnimated];

} else if ([[[UIDevice currentDevice] systemVersion] doubleValue] < 3.2) {

    MPMoviePlayerController *player = [noti object];

    [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:player];

    [player stop];

    [player release];

        }

}

Creative Commons License
Creative Commons License
Posted by 지오아빠^^