如何从头停止 MPMoviePlayerViewController

How to stop MPMoviePlayerViewController from the beginning

我想在 iOS 应用中转到下一个 ViewController 时播放电影。

这条线是我写的

 NSURL *filePath = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"movie10" ofType:@"mp4"]];

    MPMPlayerController = [[MPMoviePlayerViewController alloc]initWithContentURL:filePath ];
    MPMPlayerController.moviePlayer.backgroundView.backgroundColor = [UIColor clearColor];
    MPMPlayerController.moviePlayer.controlStyle = MPMovieControlStyleNone;
    //MPMPlayerController.view.frame = self.view.frame;
    MPMPlayerController.view.frame = CGRectMake(0, 0, 320, 600);

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(splashMoviePlayBackDidFinish:)
                                                 name:MPMoviePlayerPlaybackDidFinishNotification
                                               object:nil];

    [[NSNotificationCenter defaultCenter] removeObserver:MPMPlayerController
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:MPMPlayerController.moviePlayer];

    MPMPlayerController.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
    [MPMPlayerController.moviePlayer setFullscreen:YES animated:NO];

    [self.view addSubview:MPMPlayerController.view];

    [MPMPlayerController.moviePlayer pause];


- (void)splashMoviePlayBackDidFinish:(NSNotification *)notification
{
    UIView *fadeView = [[UIView alloc]initWithFrame:self.view.frame];
    fadeView.backgroundColor = [UIColor blackColor];
    fadeView.alpha = 0.0f;
    [self.view addSubview:fadeView];

    // Fadeout & remove
    [UIView animateWithDuration:0.5f
                     animations:^{
                         fadeView.alpha = 1.0;
                     }
                     completion:^(BOOL finished){
                         [fadeView removeFromSuperview];

                         [[NSNotificationCenter defaultCenter] removeObserver:self];
                         [MPMPlayerController.view removeFromSuperview];
                     }];
}


-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    if ((MPMPlayerController.moviePlayer.playbackState==MPMoviePlaybackStateStopped)||(MPMPlayerController.moviePlayer.playbackState==MPMoviePlaybackStatePaused))
    {
        [MPMPlayerController.moviePlayer play];
    }
    else
    {
        [MPMPlayerController.moviePlayer pause];
    }
}

但是当 ViewController 出现时电影并没有停止(暂停)并从头开始播放。 (当我触摸视图时,电影暂停。当我触摸那里时,电影再次播放)

电影从头停止怎么办?

默认 属性“shouldAutoplay”可用于 MMPPlayerController

代码下方的用户::

MPMPlayerController = [[MPMoviePlayerViewController alloc]initWithContentURL:filePath ];
MPMPlayerController.moviePlayer.backgroundView.backgroundColor = [UIColor clearColor];
MPMPlayerController.moviePlayer.controlStyle = MPMovieControlStyleNone;
//MPMPlayerController.view.frame = self.view.frame;
MPMPlayerController.view.frame = CGRectMake(0, 0, 320, 600);

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(splashMoviePlayBackDidFinish:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:nil];

[[NSNotificationCenter defaultCenter] removeObserver:MPMPlayerController
                                                name:MPMoviePlayerPlaybackDidFinishNotification
                                              object:MPMPlayerController.moviePlayer];

MPMPlayerController.moviePlayer.scalingMode = MPMovieScalingModeAspectFill;
[MPMPlayerController.moviePlayer setFullscreen:YES animated:NO];

//*** Change
[MPMPlayerController.moviePlayer setShouldAutoplay:NO]
//***

[self.view addSubview:MPMPlayerController.view];

[MPMPlayerController.moviePlayer pause];