** 개인적 메모입니다. 태클 사절 **
Apple made significant changes to the MPMoviePlayerController API:s in iOS 3.2. Before, all you had to do was to initialize the MPMoviePlayerController and call play. Now things are a bit more complicated because videos can be played on a portion of the screen (good for the iPad) and not just in full screen mode.
But if all you want is to play a video in full-screen mode on all versions of the OS, then here’s some code:
- NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:introVideoFileName ofType:@""]];
- MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
- // Register to receive a notification when the movie has finished playing.
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(moviePlayBackDidFinish:)
- name:MPMoviePlayerPlaybackDidFinishNotification
- object:moviePlayer];
- if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) {
- // Use the new 3.2 style API
- moviePlayer.controlStyle = MPMovieControlStyleNone;
- moviePlayer.shouldAutoplay = YES;
- [self.view addSubview:moviePlayer.view];
- [moviePlayer setFullscreen:YES animated:YES];
- } else {
- // Use the old 2.0 style API
- moviePlayer.movieControlMode = MPMovieControlModeHidden;
- [moviePlayer play];
- }
- - (void) moviePlayBackDidFinish:(NSNotification*)notification {
- MPMoviePlayerController *moviePlayer = [notification object];
- [[NSNotificationCenter defaultCenter] removeObserver:self
- name:MPMoviePlayerPlaybackDidFinishNotification
- object:moviePlayer];
- // If the moviePlayer.view was added to the view, it needs to be removed
- if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) {
- [moviePlayer.view removeFromSuperview];
- }
- [moviePlayer release];
- }
Recently I’ve been doing some development using cocos2d and I had to make some small changes to the code. (If your app is in portrait mode, then you may not have to do the rotation transform shown below.)
- NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:introVideoFileName ofType:@""]];
- MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
- // Register to receive a notification when the movie has finished playing.
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(moviePlayBackDidFinish:)
- name:MPMoviePlayerPlaybackDidFinishNotification
- object:moviePlayer];
- if ([moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) {
- // Use the new 3.2 style API
- moviePlayer.controlStyle = MPMovieControlStyleNone;
- moviePlayer.shouldAutoplay = YES;
- // This does blows up in cocos2d, so we'll resize manually
- // [moviePlayer setFullscreen:YES animated:YES];
- [moviePlayer.view setTransform:CGAffineTransformMakeRotation((float)M_PI_2)];
- CGSize winSize = [[CCDirector sharedDirector] winSize];
- moviePlayer.view.frame = CGRectMake(0, 0, winSize.height, winSize.width);// width and height are swapped after rotation
- [[[CCDirector sharedDirector] openGLView] addSubview:moviePlayer.view];
- } else {
- // Use the old 2.0 style API
- moviePlayer.movieControlMode = MPMovieControlModeHidden;
- [moviePlayer play];
- }
'Program > iOS' 카테고리의 다른 글
iOS5 - "armv6" UPLOAD Error (2) | 2011.11.04 |
---|---|
Mac - Inactive memory can be slow to free up (1) | 2011.09.26 |
iOS - CGContextRef / CGImageRef Image Orientation / Mask / Cropping (2) | 2011.08.26 |
iOS - OTA ( Over the Air AdHoc ) 2 (2) | 2011.08.25 |
iOS - 인증되지 않은 다른 맥에서 개발하기 (4) | 2011.08.22 |