我在3.1.2中遇到了MPMoviePlayerController的问题。
如果我在时取消播放器仍在加载,播放器会关闭。但是,视频会在后台播放片刻。阻止它的唯一方法是播放另一个视频或关闭应用程序。这似乎在3.2 +中工作正常。
这就是我正在做的事情:
- (void)loadMoviePlayer
{
// Register to receive a notification when the movie has finished playing.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(moviePlayBackDidFinish:)
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
if ([NSClassFromString(@"MPMoviePlayerController") instancesRespondToSelector:@selector(view)])
{
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 30200
// running iOS 3.2 or better
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:@"http://www.mysite.com/myvideo.m3u8"]];
[moviePlayer.view setBackgroundColor:[UIColor blackColor]];
[moviePlayer.moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
// [moviePlayer.moviePlayer setControlStyle:MPMovieControlStyleNone];
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
[moviePlayer.moviePlayer prepareToPlay];
[moviePlayer.moviePlayer play];
#endif
}
else
{
MPMoviePlayerController *mMPPlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"http://www.mysite.com/myvideo.m3u8"]];
mMPPlayer.scalingMode=MPMovieScalingModeFill;
mMPPlayer.backgroundColor=[UIColor blackColor];
[mMPPlayer play];
}
}
- (void) moviePlayBackDidFinish:(NSNotification*)notification
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque];
[[UIApplication sharedApplication] setStatusBarHidden:NO];
// Remove observer
[[NSNotificationCenter defaultCenter]
removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:nil];
[self dismissModalViewControllerAnimated:YES];
}
今天早上我添加了moviePlayBackDidFinish。当我点击取消时它被调用,但dismissModalViewControllerAnimated似乎什么也没做。我也尝试过removeFromSuperView,但我的播放器不会响应。
那么,如何在点击“取消”后确保播放器不播放?
提前致谢。
答案 0 :(得分:5)
您可能在MPMoviePlayerController中遇到过一个旧错误。在这些日子里,我们实际上必须在播放适当的内容后播放几乎空的(黑色,静音)M4V,以确保玩家在某些阶段停止时不会尝试在后台继续播放。该错误表现在可听见的声音中,但没有中止/停止视频的图片。
然而,停止时还有一些值得尝试的事情(假设您的MPMoviePlayerController实例名为moviePlayer);
moviePlayer.currentPlaybackTime = moviePlayer.duration;
[moviePlayer stop];
答案 1 :(得分:4)
在我的情况下,我发现设置以下行最终会阻止电影播放器播放:
moviePlayer.contentURL = nil;
(使用moviePlayer作为MPMoviePlayerController的实例)。