【问题标题】:MPMoviePlayerController failed with itemFailedToPlayToEndMPMoviePlayerController 因 itemFailedToPlayToEnd 而失败
【发布时间】:2014-05-12 00:18:23
【问题描述】:

我从我的 iPhone 照片库中检索了电影文件,并将它们保存到我的应用程序的 Documents 目录中。当我单击一个电影文件时,我想使用 MPMoviePlayerController 来播放它。不幸的是,它无法播放电影文件并出现这样的错误:

_itemFailedToPlayToEnd: {
    kind = 1;
    new = 2;
    old = 0;
  }

我找了很久才解决这个问题。有人说格式可能不支持。电影文件是从照片库中检索的,所以格式应该没问题。另外,我将文件复制到 NSBundle 并且 MPMoviePlayerController 可以播放它。所以文件没问题。以下是我的代码:

    NSString *newstr = [mFilePath stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    DLog(@"the raw is %@ the newstr is %@", mFilePath, newstr);
    NSURL *url = [NSURL URLWithString:newstr];
    DLog(@"the url is %@", url);
#if 0
    NSBundle *bundle = [NSBundle mainBundle];
    if (bundle) {
        NSString *path = [bundle pathForResource:@"test" ofType:@"MOV"];
        if (path) {
            url = [NSURL fileURLWithPath:path];
            DLog(@"the new url is %@", url);
        }
    }
#endif

    mPlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
    [mPlayer setMovieSourceType:MPMovieSourceTypeFile];
    [mPlayer prepareToPlay];
    [mPlayer.view setFrame:self.view.bounds];

    [mPlayer play];
    [self.view addSubview:mPlayer.view];

【问题讨论】:

  • 得到同样的错误,但当我直接从服务器播放时没有......

标签: mpmovieplayercontroller movie video-player


【解决方案1】:

变化:

 NSURL *url = [NSURL URLWithString:path];

 NSURL *url = [NSURL fileURLWithPath:path];

帮我修好了,然后:

mPlayer.contentURL = url;
[mPlayer prepareToPlay];

但是你已经正确地做到了。我创建了一次 mPlayer,然后为不同的视频移动 contentURL(而不是 alloc + initWithContentURL)。你试过吗?

【讨论】:

    猜你喜欢
    • 2013-10-06
    • 1970-01-01
    • 2018-02-16
    • 2012-10-03
    • 2014-07-16
    • 2021-11-23
    • 2018-10-04
    • 2020-03-23
    • 1970-01-01
    相关资源
    最近更新 更多