【发布时间】:2016-12-31 20:32:00
【问题描述】:
我在 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,但我的播放器没有响应。
那么,如何确保玩家在点击“取消”后不玩呢?
提前致谢。
【问题讨论】:
标签: iphone mpmovieplayercontroller