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

时间:2012-10-08 17:35:14

标签: video ios6 mpmovieplayercontroller movie nsnotification

我可能没有把我的头衔措辞得很好,也许更正确的说我的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`

1 个答案:

答案 0 :(得分:18)

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

player.fullscreen = NO;

从superview中删除视图之前