0

我需要从视图中删除 MPMoviePlayerController。我试过这个。

[moviePlayerController stop];
[moviePlayerController.view removeFromSuperview];

视频停止,但视图未删除。我猜[moviePlayerController.view removeFromSuperview];是行不通的。可能是什么原因 ?这个问题的任何解决方案..?

谢谢。

4

6 回答 6

1

这是一个已知问题,您使用的是 ARC,然后您必须将播放器添加到您的 .h 中,因为如果您在本地声明它仍然会被释放。

@property (nonatomic, strong) MPMoviePlayerController* controller;

添加视图:

self.controller = [[MPMoviePlayerController alloc] initWithContentURL:YOURVIDEOURL];

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

self.controller.controlStyle = MPMovieControlStyleDefault;
self.controller.shouldAutoplay = YES;

[self.view addSubview:self.controller.view];
[self.controller setFullscreen:YES animated:YES];

然后删除视图:

- (void) moviePlayBackDidFinish:(NSNotification*)notification {

if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation))
{

    [[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationPortrait animated:NO];

}

MPMoviePlayerController *player = [notification object];
[[NSNotificationCenter defaultCenter]
 removeObserver:self
 name:MPMoviePlayerPlaybackDidFinishNotification
 object:player];

if ([player
     respondsToSelector:@selector(setFullscreen:animated:)])
{
    [player.view removeFromSuperview];
}
}
于 2013-05-14T20:42:00.513 回答
1

这个问题通常是因为播放器被释放。解决方案是在.h中声明播放器实例,属性为“strong”。

@property (nonatomic,strong) MPMoviePlayerController* mpController;
于 2014-10-20T12:49:04.553 回答
0

不完全确定,但由于我遇到了由于自动解除分配而导致电影播放器​​没有出现的问题,我想你可以设置moviePlayerController = nil;.

不完全确定视图是否会消失,但值得一试!

于 2012-10-16T07:15:40.170 回答
0

尝试dismissViewController:animated: 这可能会奏效。

于 2012-10-16T07:21:40.353 回答
0
[moviePlayerController stop];
[moviePlayerController setContentURL:nil];
[moviePlayerController.view removeFromSuperview];

这在我的项目中运行良好

于 2012-10-16T07:27:26.107 回答
0

对我来说,我尝试了所有这些: [moviePlayer stop]; [moviePlayer setContentURL:nil]; [moviePlayer.view removeFromSuperview]; moviePlayer = nil;

没有任何效果。我发现它必须由于我的 MPMoviePlayerController 进入全屏。修复?

        [moviePlayer setFullscreen:NO animated:YES];
于 2013-04-18T12:33:27.690 回答