Objective c MPMoviePlayer不会在[moviePlayer.view removeFromSuperview]和[moviePlayer release]上消失
我的MPMoviePlayerController有问题。当我观看视频并点击左上角的“完成”按钮时,MoviePlayer不会消失,即使代码似乎被调用:Objective c MPMoviePlayer不会在[moviePlayer.view removeFromSuperview]和[moviePlayer release]上消失,objective-c,cocoa-touch,uiview,notifications,mpmovieplayercontroller,Objective C,Cocoa Touch,Uiview,Notifications,Mpmovieplayercontroller,我的MPMoviePlayerController有问题。当我观看视频并点击左上角的“完成”按钮时,MoviePlayer不会消失,即使代码似乎被调用: NSURL *url = [NSURL URLWithString:article.enclosureLink]; MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
NSURL *url = [NSURL URLWithString:article.enclosureLink];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
// Set movie player layout
[moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
[moviePlayer setFullscreen:YES];
// May help to reduce latency
[moviePlayer prepareToPlay];
// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayer];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(movieReadyToPlay:)
name:MPMoviePlayerLoadStateDidChangeNotification
object:moviePlayer];
和选择器:
- (void) movieReadyToPlay:(NSNotification*)notification {
MPMoviePlayerController *moviePlayer = [notification object];
if(moviePlayer.loadState == MPMovieLoadStatePlayable){
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerLoadStateDidChangeNotification object:moviePlayer];
moviePlayer.controlStyle = MPMovieControlStyleFullscreen;
//moviePlayer.shouldAutoplay = YES;
[self.view addSubview:moviePlayer.view];
[moviePlayer setFullscreen:YES animated:YES];
[moviePlayer play];
}
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification {
MPMoviePlayerController *moviePlayer = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayer];
[moviePlayer setFullscreen:NO animated:YES];
[moviePlayer.view removeFromSuperview];
[moviePlayer release];
NSLog(@"Finished movie!");
}
在我看来,这是一个非常直接的代码,但我必须犯一个愚蠢的错误。NSLog显示函数被调用,但播放器停留在原地,无法摆脱它
而且,玩家在被指控的释放后仍然可以操作这一事实似乎表明有一些根本性的错误,我只是不明白是什么
有人有什么建议吗
[更新:]
奇怪的是,在iPhone模拟器中,它工作得很好
[更新2:]
我尝试并创建了一个特定的UIviewcontroller,尽管它不是我想要的方式,因为动画不好。但我学到的是我也有同样的问题。这似乎与解雇球员有关,但它又重新开始了
当我将[self.moviePlayer设置为全屏:是动画:是];在viewDidApear中,单击播放器中的“完成”按钮,当我点击“完成”按钮时,视频将重新开始(viewDidAppear将再次调用)。在我看来,有什么东西被触发了,让视频重新开始
如果我把它放在viewDidLoad上,那么系统可以工作,但是图形是混合和混乱的
任何帮助都是非常非常感谢的,因为我现在花了两天的时间在这件事上,没有任何头绪 添加
[moviePlayer stop]
以前
[moviePlayer.view removeFromSuperview]
可能有用
更新:
如果这不起作用,请在删除子视图之前尝试将controlstyle设置为MPMovieControlStyleNone。大多数情况下,controlstyle会导致此类问题。对于我,我尝试了以下所有方法:
[电影播放器停止];
[moviePlayer setContentURL:nil];
[moviePlayer.view从SuperView移除];
电影播放器=零代码>
什么都没用。我发现这是由于我的MPMoviePlayerController进入全屏。修复
[moviePlayer setFullscreen:NO animated:YES];
谢谢,我试过了,但没用。也许这是一个bug,但现在我用的是MPMoviePlayerViewController,虽然不是我想要的,这似乎有效。@Luuk:好的。事实上,我们必须解决MPMovieplayerController中存在的许多漏洞。苹果似乎在更高版本的iOS中解决了这些漏洞,但在以前的版本中不起作用。我只想指出,在iOS 6中,这种方法调用stop,然后从superview中删除播放器的视图,即使之前将控件样式设置为“无”,仍然不起作用=/@Will:dots-work的确切含义是什么?玩家没有停止游戏?你找到解决办法了吗?我在iOS 5.0上也遇到了同样的问题,我搬到了MPMoviePlayerServiceWController,这是一个完成了这个技巧而不是我自己的