简体   繁体   中英

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.

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];

Did you try setting the view frame?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM