Iphone MPMoviePlayerController don';我不想工作
我正在使用cocos2d,我想播放一部电影 我创建了一个Iphone MPMoviePlayerController don';我不想工作,iphone,objective-c,ios,cocos2d-iphone,mpmovieplayercontroller,Iphone,Objective C,Ios,Cocos2d Iphone,Mpmovieplayercontroller,我正在使用cocos2d,我想播放一部电影 我创建了一个CCLayer子类,并重新实现了它的init方法,如下所示: -(id) init { self = [super init]; if (self) { NSURL *url = [NSURL fileURLWithPath:@"common/test-movie.mp4"]; MPMoviePlayerController *player = [[MPMoviePlayerContr
CCLayer
子类,并重新实现了它的init
方法,如下所示:
-(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;
}
我已经运行了[[CCDirector sharedDirector]runWithScene:scene]场景中的代码>仅包含此层。但是什么也没有显示:(只是一个黑屏
编辑
此外,它总是为每部电影返回0个持续时间。我甚至尝试从iPhone的摄像头播放一段视频-结果相同。您尝试过设置视图框吗
id parentView = [[CCDirector sharedDirector] openGLView];
[parentView addSubview:[player view]];
[[player view] setFrame:[parentView bounds]];
问题出在NSURL中-我是以不正确的方式创建它的。下面是正确的代码:
NSString *rootPath = [[NSBundle mainBundle] resourcePath];
NSString *filePath = [rootPath stringByAppendingPathComponent:@"test-movie.mp4"];
NSURL *url = [NSURL fileURLWithPath:filePath isDirectory:NO];