首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >媒体播放器框架不能在iOS 6中播放视频

媒体播放器框架不能在iOS 6中播放视频
EN

Stack Overflow用户
提问于 2012-11-06 11:27:13
回答 3查看 3.5K关注 0票数 2

我正在使用iOS 6中包含的mediaplayer框架来尝试从应用程序中播放电影。我导入,然后:

代码语言:javascript
复制
-(IBAction)playMovie:(id)sender
{
    NSString *filepath = [[NSBundle mainBundle] pathForResource:@"buyTutorial" ofType:@"mov"];
    NSURL *fileURL = [NSURL fileURLWithPath:filepath];
    MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
    [self.view addSubview:moviePlayerController.view];
    moviePlayerController.fullscreen = YES;
    [moviePlayerController play];
}

当调用此函数时,视图转到空白屏幕并无限加载。我已经尝试了这个实现的许多其他版本,结果各不相同,都失败了。is特殊情况下的日志为:

代码语言:javascript
复制
2012-11-05 21:19:27.900 [MPAVController] Autoplay: Disabling autoplay for pause
2012-11-05 21:19:27.902 [MPAVController] Autoplay: Disabling autoplay
2012-11-05 21:19:27.977 [MPAVController] Autoplay: Disabling autoplay for pause
2012-11-05 21:19:27.978 [MPAVController] Autoplay: Disabling autoplay
2012-11-05 21:19:27.984 [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
2012-11-05 21:19:28.156 [MPAVController] Autoplay: Enabling autoplay

有关于这个事业的想法吗?这是我第一次尝试玩视频,在这一点上它被证明是一场噩梦。

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2012-11-06 21:11:07

在.h文件中添加以下内容

代码语言:javascript
复制
@property (nonatomic, strong) MPMoviePlayerController *controller;

尝尝这个

代码语言:javascript
复制
 -(IBAction)playMovie:(id)sender
    {
        NSString *filepath = [[NSBundle mainBundle] pathForResource:@"buyTutorial" ofType:@"mov"];
        NSURL *fileURL = [NSURL fileURLWithPath:filepath];
        MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc] initWithContentURL:fileURL];
        [self.view addSubview:moviePlayerController.view];
        moviePlayerController.fullscreen = YES;
    [moviePlayerController prepareToPlay];
        [moviePlayerController play];
[self setController:moviePlayerController];
    }
票数 9
EN

Stack Overflow用户

发布于 2013-01-17 10:55:52

代码语言:javascript
复制
Am facing the same issue, you can else try playing it on the web view. 

   NSURL *url = [NSURL fileURLWithPath:self.filePath];
   NSURLRequest *request = [NSURLRequest requestWithURL:url];
    [self.docWebView loadRequest:request];
票数 0
EN

Stack Overflow用户

发布于 2014-08-14 12:24:07

代码的问题在于变量"moviePlayerController“只是局部作用域,所以在调用[moviePlayerController play];并退出函数后,局部变量立即被释放(因为这里有一个异步操作,其中包含从队列播放的play方法)。它不再保留引用URL的内容。所以你会看到一个黑屏和一个不定式“正在加载...”

您需要声明class的一个实例变量,并将内容从局部变量复制到class的属性,就像上面@iAppDeveloper中的示例代码一样。它应该是有效的!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13243903

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档