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`
4

1 回答 1

18

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

player.fullscreen = NO;

在从超级视图中删除视图之前

于 2012-10-11T18:14:44.433 回答