Monday, September 6, 2010

cocos2d and MPMoviePlayerController crash

Programmer Question

Hello,



I try to show an intro and replaceScene when the intro has finished. But, when the movie finish, app is crashing on [[CCDirector sharedDirector] replaceScene:[CCFadeTransition transitionWithDuration:0.5f scene:[MenuScene scene]]];.



code is;



- (void) moviePlayBackDidFinish {


[self.moviePlayer stop];



[[CCDirector sharedDirector] replaceScene:[CCFadeTransition transitionWithDuration:0.5f scene:[MenuScene scene]]];
}



-(id) init
{



// always call "super" init
// Apple recommends to re-assign "self" with the "super" return value
if( (self=[super init] )) {
//pencere boyutu elde ediliyor



NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"intro" ofType:@"mp4"]];
self.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:self.moviePlayer];



if ([self.moviePlayer respondsToSelector:@selector(setFullscreen:animated:)]) {

// Use the new 3.2 style API

self.moviePlayer.controlStyle = MPMovieControlStyleNone;

self.moviePlayer.shouldAutoplay = YES;

// This does blows up in cocos2d, so we'll resize manually

// [moviePlayer setFullscreen:YES animated:YES];

[self.moviePlayer.view setTransform:CGAffineTransformMakeRotation((float)M_PI_2)];

CGSize winSize = [[CCDirector sharedDirector] winSize];

self.moviePlayer.view.frame = CGRectMake(0, 0, winSize.height, winSize.width);// width and height are swapped after rotation

[[[CCDirector sharedDirector] openGLView] addSubview:self.moviePlayer.view];

} else {

// Use the old 2.0 style API

self.moviePlayer.movieControlMode = MPMovieControlModeHidden;

[self.moviePlayer play];

}



}



return self;
}



Find the answer here

No comments:

Post a Comment

LinkWithin

Related Posts with Thumbnails