I’m using cocos2d and i want to play a movie.
I’ve created a CCLayer subclass and reimplemented it’s init method like this:
-(id) init
{
self = [super init];
if (self)
{
NSURL *url = [NSURL fileURLWithPath:@"common/test-movie.mp4"];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:url];
[[[CCDirector sharedDirector] openGLView] addSubview:[player view]];
[player play];
}
return self;
}
I’ve run [[CCDirector sharedDirector] runWithScene:scene]; with the scene contains only this layer. But nothing is displayed 🙁 Just a black screen.
EDIT
Also it always returns 0 duration for every movie. I’ve even tried to play a video from iPhone’s camera – the same result.
The problem was in NSURL – i was created it in not right way. Here is the right code: