MPMoviePlayerController不会在iOS 1上使用iOS 5循环

时间:2012-07-30 13:33:41

标签: ipad ios5 mpmovieplayercontroller

我有一部短片可以在我的视角背景中循环播放。我使用MPMoviePlayerController播放电影。 repeatMode设置为MPMovieRepeatModeOne,这在iPad 2,3和Simulator中工作正常。然而,在iPad 1上,电影循环一次并在第二次播放后立即停止。该项目是iOS 5 w / o ARC(从GM到5.1.1测试)。

- (void)loadVideo {
    NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"movieFileName.m4v" ofType:nil];
    self.videoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:urlStr]];
    self.videoPlayer.controlStyle = MPMovieControlStyleNone;
    self.videoPlayer.scalingMode = MPMovieScalingModeFill;
    self.videoPlayer.repeatMode = MPMovieRepeatModeOne;
    self.videoPlayer.view.userInteractionEnabled = NO;
    [self.videoPlayer.view setFrame:self.movieContainer.bounds];
    [self.movieContainer addSubview:self.videoPlayer.view];
}

如何在iPad 1上播放电影?

1 个答案:

答案 0 :(得分:1)

经过多次尝试后,我终于找到了解决这个问题的方法:

在注册已更改的播放状态MPMoviePlayerPlaybackStateDidChangeNotification的通知后,电影无休止地循环,并且在iPad 2上第二次播放后不会停止。请记住,这种行为不会发生在iPad 2,3或模拟器。

为通知执行的选择器不能为空。只需分配一个bool或其他东西。上面的扩展代码是:

- (void)loadVideo {
    // Create the controller
    NSString *urlStr = [[NSBundle mainBundle] pathForResource:@"movieFileName.m4v" ofType:nil];
    NSURL *url = [NSURL fileURLWithPath:urlStr];
    self.videoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];

    // Configure the controller
    self.videoPlayer.controlStyle = MPMovieControlStyleNone;
    self.videoPlayer.scalingMode = MPMovieScalingModeFill;
    self.videoPlayer.repeatMode = MPMovieRepeatModeOne;
    self.videoPlayer.view.userInteractionEnabled = NO;
    [self.videoPlayer.view setFrame:self.movieContainer.bounds];

    // Register for notifications
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(moviePlayerNotification:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:videoPlayer];
    self.listeningToMoviePlayerNotifications = YES;

    // Add its view to the hierarchy
    [self.movieContainer addSubview:self.videoPlayer.view];
}

- (void)moviePlayerNotification:(NSDictionary *)userInfo {
    // Do anything here, for example re-assign the listeningToMoviePlayerNotification-BOOL
    self.listeningToMoviePlayerNotifications = YES;
}