【问题标题】:mediaplayer framework not playing video in iOS 6mediaplayer 框架不在 iOS 6 中播放视频
【发布时间】:2012-10-25 23:38:33
【问题描述】:

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

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

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

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

对原因有想法吗?这是我第一次尝试播放视频,结果证明这是一场噩梦。

【问题讨论】:

  • 尝试拨打[moviePlayerController prepareToPlay];
  • 添加了 [moviePlayerController prepareToPlay] 但这并没有改变结果。
  • 电影播放器​​集视图的分配和获取路径确实加载了,只调用[moviePlayerController play]点击按钮
  • @NANNAV 我试过了,还是不行。不同的错误...

标签: iphone objective-c ios media-player loading


【解决方案1】:

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

@property (nonatomic, strong) MPMoviePlayerController *controller;

试试这个

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

【讨论】:

  • 无法构建您的代码,因为类不包含任何方法 setController
【解决方案2】:
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];

【讨论】:

    【解决方案3】:

    你的代码的问题是变量“moviePlayerController”只是局部范围,所以在你调用[moviePlayerController play];并退出函数后,局部变量被释放(因为这里有一个带有播放方法的异步操作从队列中)。它不再让内容引用 URL。所以你会看到一个黑屏和一个不定式“Loading...”

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-16
      • 1970-01-01
      相关资源
      最近更新 更多