我在 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。当我点击取消时它会被调用,但解雇ModalViewControllerAnimated似乎没有做任何事情。我也尝试了removeFromSuperView,但我的播放器没有响应。
那么,如何确保玩家在点击“取消”后不会玩游戏?
提前致谢。
最佳答案
您可能在 MPMoviePlayerController 中遇到了一个旧错误。过去,我们实际上必须在播放正确的内容后播放几乎空的(黑色、静音)M4V,以确保播放器在某些阶段停止时不会尝试在后台继续播放。该错误表现为可听到声音,但没有中止/停止的视频的图片。
然而,停止时还有一些值得尝试的事情(假设您的 MPMoviePlayerController 实例称为 moviePlayer);
- 将当前播放位置设置为完整的影片时长
moviePlayer.currentPlaybackTime = moviePlayer.duration;
- 在通知处理程序中发送另一个停止
[moviePlayer stop];
关于iphone - MPMoviePlayerController 在 3.1.2 中取消后播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5637956/