MPMoviePlayerController在播放完毕后不会自动关闭电影(iOS 6)

10

我的标题可能表达得不够清楚,更准确地说,我的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个回答

18
我也遇到了这个问题。要在 moviePlayBackDidFinish 中进行修复,只需添加

player.fullscreen = NO;

从父视图中移除视图之前


2
我需要反过来。我希望MPMoviePlayerController不会自动关闭。用户可以使用“完成”按钮关闭它。 - Amit Battan

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接