MPMoviePlayer关闭全屏导致黑色视图/阻止

时间:2012-11-28 13:05:39

标签: ios video mpmovieplayer

我正在播放来自MPMoviePlayer的视频(不是全屏),当我进入全屏时,视频会继续播放并显示全屏。 但是当我再次关闭全屏时,我只能看到“小”视频正在播放的地方的黑色背景。它没有回应接触或任何事情。

我从不在我的播放器上停止停止,并且没有声明viewdiddissapear(或类似)函数。 电影播放器​​也没有发布。

我想在关闭全屏时继续播放视频。有什么想法吗?

**编辑 它可以在iPad 1上运行,但不适用于iPad 2 ......很奇怪......我需要它才能在所有功能上运行。

电影播放器​​初始化:

NSURL *fileURL = [NSURL fileURLWithPath:filePath];
self.moviePlayer = [[MPMoviePlayerController alloc] init];
self.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
self.moviePlayer.controlStyle = MPMovieControlStyleEmbedded;
self.moviePlayer.contentURL = fileURL;
self.moviePlayer.backgroundView.backgroundColor = [UIColor blackColor];
self.moviePlayer.shouldAutoplay = YES;
[self.moviePlayer.view setFrame:CGRectMake(1024, floorf((self.view.bounds.size.height / 2) - (318 / 2)), 425, 318)];
[self.moviePlayer prepareToPlay];


[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(MPMoviePlayerLoadStateDidChange:)
                                             name:MPMoviePlayerLoadStateDidChangeNotification
                                           object:self.moviePlayer];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(MPMoviePlayerDidFinish:)
                                             name:MPMoviePlayerPlaybackStateDidChangeNotification
                                           object:self.moviePlayer];

[self.view addSubview:self.moviePlayer.view];
[self.view bringSubviewToFront:self.moviePlayer.view];

[UIView animateWithDuration:0.25
                      delay:0.0
                    options:UIViewAnimationCurveEaseOut
                 animations:^{
                     self.moviePlayer.view.transform = CGAffineTransformIdentity;
                     self.moviePlayer.view.position = CGPointMake(floorf(787 - (self.moviePlayer.view.frame.size.width / 2)),
                                                      self.moviePlayer.view.position.y);
                 }
                 completion:nil];

通知

- (void)MPMoviePlayerLoadStateDidChange:(NSNotification *)notification
{
NSLog(@"Loadstate changed");
if((self.moviePlayer.loadState & MPMovieLoadStatePlaythroughOK) == MPMovieLoadStatePlaythroughOK)
{
    [self.moviePlayer play];
}
}

- (void)MPMoviePlayerDidFinish:(NSNotification *)notification
{
MPMovieFinishReason finishReason = (MPMovieFinishReason) [notification.userInfo objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];

switch(finishReason)
{
    case MPMovieFinishReasonPlaybackError: NSLog(@"Stopped playback due to error");
    case MPMovieFinishReasonPlaybackEnded: NSLog(@"I just quitted");
    case MPMovieFinishReasonUserExited: NSLog(@"User quitted");
}
}

0 个答案:

没有答案