Andrew
Andrew

Reputation: 24846

MPMoviePlayerController don't want to work

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.

Upvotes: 2

Views: 640

Answers (2)

Andrew
Andrew

Reputation: 24846

The problem was in NSURL - i was created it in not right way. Here is the right code:

NSString *rootPath = [[NSBundle mainBundle] resourcePath];
NSString *filePath = [rootPath stringByAppendingPathComponent:@"test-movie.mp4"];
NSURL *url = [NSURL fileURLWithPath:filePath isDirectory:NO];

Upvotes: 3

zoul
zoul

Reputation: 104065

Did you try setting the view frame?

id parentView = [[CCDirector sharedDirector] openGLView];
[parentView addSubview:[player view]];
[[player view] setFrame:[parentView bounds]];

Upvotes: 1

Related Questions