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]];
精彩评论