完成播放后,MPMoviePlayerController不会自动关闭电影(ios 6)

rob*_*ino 10 video movie mpmovieplayercontroller nsnotification ios6

我可能没有把我的头衔措辞得很好,也许更正确的说我的NSNotification并没有在完​​成比赛后放弃我的电影观点.我发现其他人有这个问题,但没有解决方案,似乎它可能是iOS 6的问题,这就是我正在运行的.

视频完成播放后,您需要按"完成"才能解除,但我希望它能自动关闭,因为我将使用MPMovieControlStyleNone一旦我将其整理出来.这是我的代码,未使用的部分被删除:`

#import "MovieViewController.h"

@interface MovieViewController ()

@end

@implementation MovieViewController

@synthesize moviePlayer = _moviePlayer;

- (IBAction)playMovie:(id)sender
{
    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                         pathForResource:@"TestMovie" ofType:@"mov"]];
    _moviePlayer =
    [[MPMoviePlayerController alloc]
     initWithContentURL:url];

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

    _moviePlayer.controlStyle = MPMovieControlStyleDefault;
    _moviePlayer.shouldAutoplay = YES;
    [self.view addSubview:_moviePlayer.view];
    [_moviePlayer setFullscreen:YES animated:NO];
}

- (void) moviePlayBackDidFinish:(NSNotification*)notification {

    MPMoviePlayerController *player = [notification object];

    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:player];

    if ([player
         respondsToSelector:@selector(setFullscreen:animated:)])
    {
        [player.view removeFromSuperview];
    }
}

@end`
Run Code Online (Sandbox Code Playgroud)

小智 18

有这个问题以及修复moviePlayBackDidFinish只需添加

player.fullscreen = NO;
Run Code Online (Sandbox Code Playgroud)

在从superview中删除视图之前

  • 我需要它逆转.我想MPMoviePlayerController不应该自动解散.用户可以使用*Done*按钮将其关闭 (2认同)