iOS4가 나오면서 조금씩 달라지는 API들.
역시 Upgrade에 장사없다고, 하위버전에 대한 호환이 안되는군. OS자체를 다 바꿔야 하니..ㅋㅋ
일단 아래와 같이 3.2를 기준으로 하위 버전과 상위버전에 대한 처리를 다르게 해 본다.
/**
* Video Play
* @param data : 인식된 data
*/
- (void) playMovie: (NSString *) dataValue
{
NSString *movieURL;
movieURL = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"mp4"];
/// iPhone Device 버전에 따라 동영상 Play
if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 3.2) {
/// MPMoviePlayerViewController 초기화
MPMoviePlayerViewController *playerView = [[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:movieURL]] autorelease];
playerView.view.backgroundColor = [UIColor blackColor];
playerView.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
/// 동영상 끝났을때 호출
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playbackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:playerView.moviePlayer];
/// Play the movie
[self presentMoviePlayerViewControllerAnimated:playerView];
}
else if ([[[UIDevice currentDevice] systemVersion] doubleValue] < 3.2) {
/// MPMoviePlayerController 초기화
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:movieURL]];
moviePlayer.initialPlaybackTime = 0;
moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
moviePlayer.movieControlMode = MPMovieControlModeDefault;
/// 동영상 끝났을때 호출
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playbackFinishedCB:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
/// Play the movie
[moviePlayer play];
}
}
/**
* when the movie is finished
*/
- (void) playbackFinishedCB:(NSNotification *) aNotification
{
if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 3.2) {
MPMoviePlayerController *player = [aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player stop];
[self dismissMoviePlayerViewControllerAnimated];
}
else if ([[[UIDevice currentDevice] systemVersion] doubleValue] < 3.2) {
MPMoviePlayerController *player = [aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:player];
[player stop];
[player release];
}
}