OGeek|极客世界-中国程序员成长平台

标题: iphone - MPMoviePlayerController 不想工作 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 15:52
标题: iphone - MPMoviePlayerController 不想工作

我正在使用 cocos2d,我想播放一部电影。

我创建了一个 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 的相机播放视频 - 结果相同。



Best Answer-推荐答案


问题出在 NSURL - 我创建它的方式不正确。这是正确的代码:

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

关于iphone - MPMoviePlayerController 不想工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4807669/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4