2

我正在尝试从我的资源文件加载一个 25 秒的 mp4 电影,但是当我播放它时,我的 MPMoviePlayerPlaybackDidFinishNotification 选择器会立即使用 MPMovieFinishReasonPlaybackEnded 调用。当我记录我的播放状态时,它会显示:

MPMoviePlaybackStatePlaying
MPMoviePlaybackStatePaused
MPMoviePlaybackStateStopped
MovieFinishReasonPlaybackEnded
MPMoviePlaybackStatePlaying
MPMoviePlaybackStatePaused

即使我只调用一次 play 方法。我希望有一个人可以帮助我。

-- 编辑显示我的代码:

MPMoviePlayerController* player = [[[MPMoviePlayerController alloc] initWithContentURL:movieURL] autorelease];

if (player)
{

    self.moviePlayerController = player;

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayBackDidFinish:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:player];

  [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(moviePlayerPlaybackStateDidChange:)
                                                 name:MPMoviePlayerPlaybackStateDidChangeNotification
                                               object:player];


    player.contentURL = movieURL;

    player.movieSourceType = MPMovieSourceTypeFile;

    player.controlStyle = MPMovieControlStyleNone;

    player.fullscreen = YES;

    switch (orientation) {
        case UIInterfaceOrientationLandscapeLeft:
            player.view.transform = CGAffineTransformMakeRotation(90.0f * (M_PI / 180.0f));
            break;
        case UIInterfaceOrientationLandscapeRight:
            player.view.transform = CGAffineTransformMakeRotation(-90.0f * (M_PI / 180.0f));
            break;
        default:
            break;
    }

    player.view.frame = self.view.bounds;

    [self.view addSubview:player.view];
}

[self.moviePlayerController play]
4

2 回答 2

1

self.moviePlayerController保留财产吗?如果没有,MPMoviePlayerController实例将很快被释放(由autorelease),您可能会得到类似的行为。

于 2012-09-12T13:52:07.147 回答
0

无需查看更多代码,我建议您尝试播放您知道可以播放的另一个文件。例如,从这个示例项目中获取电影:http: //developer.apple.com/library/ios/#samplecode/MoviePlayer_iPhone/Introduction/Intro.html并查看它是否可以播放。

当我尝试播放格式不正确的文件时,我也遇到了类似的事情。


嗯...我看不出有什么问题。你确定movieURL是正确的吗?你怎么得到它?

为了记录,这就是我展示电影的方式,尽管它不会产生与你正在做的完全相同的效果。

NSString *path = [[NSBundle mainBundle] pathForResource:movieFileName ofType:@"m4v"];

// If path is NULL (the resource does not exist) return to avoid crash
if (path == NULL)
    return;

NSURL *url = [NSURL fileURLWithPath:path];
MPMoviePlayerViewController *mpViewController = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
mpViewController.moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
mpViewController.moviePlayer.shouldAutoplay = YES;

// NOTE: This can sometimes crash the app in the Simulator. This is a known bug
// in xcode: http://stackoverflow.com/a/8317546/472344
[self presentMoviePlayerViewControllerAnimated:mpViewController];
[mpViewController release];
于 2012-09-11T13:15:16.413 回答