MPMoviePlayerController因itemFailedToPlayToEnd失败

问题描述 投票:2回答:1

我从我的iPhone照片库中检索了电影文件,并将它们保存到我的App`s 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个回答
0
投票

更改:

 NSURL *url = [NSURL URLWithString:path];

 NSURL *url = [NSURL fileURLWithPath:path];

为我修好了,然后:

mPlayer.contentURL = url;
[mPlayer prepareToPlay];

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

© www.soinside.com 2019 - 2024. All rights reserved.