切换视图后,MPMoviePlayerController消失

时间:2010-11-02 12:56:44

标签: ipad media mpmovieplayercontroller

我有3个电影播放器​​添加到三个不同的视图。当电影只播放几秒钟时我在视图之间随机切换时,播放器会在所有后续视图中消失。

我不会在任何地方发布我的观点,我无法弄清楚为什么我的玩家会消失

这是我在View id Load方法中使用的代码以及通知方法。

movieUrl =[[NSBundle mainBundle] pathForResource:@"Old Spice-Ad" ofType:@"mp4"];

player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:movieUrl]];

player.view.frame =CGRectMake(38,380,211,122);

[self.view addSubview:player.view];

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



- (void)moviePlayBackDidFinish:(NSNotification *)notification {
    MPMoviePlayerController *theMovie = [notification object];
    [[NSNotificationCenter defaultCenter] removeObserver:self
                                                    name:MPMoviePlayerPlaybackDidFinishNotification
                                                  object:theMovie];
    [theMovie stop];
    [theMovie release];
}

1 个答案:

答案 0 :(得分:1)

在MPMoviePlayerController类中引用:

注意:虽然您可以创建多个MPMoviePlayerController对象并在界面中显示其视图,但一次只能有一个电影播放器​​播放其电影。