use*_*519 2 iphone mpmovieplayercontroller
我在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];
}
Run Code Online (Sandbox Code Playgroud)
我今天早上添加了moviePlayBackDidFinish.当我点击取消时它被调用,但dismissModalViewControllerAnimated似乎什么也没做.我也尝试过removeFromSuperView,但我的播放器不会响应.
那么,我怎样才能确保玩家在点击"取消"后不玩?
提前致谢.
您可能在MPMoviePlayerController中遇到了一个旧错误.在这些日子里,我们实际上必须在播放适当的内容后播放几乎空的(黑色,静音)M4V,以确保玩家在某些阶段停止时不会尝试在后台继续播放.该错误表现在可听见的声音中,但没有中止/停止视频的图片.
然而,在停止时还有一些值得尝试的事情(假设你的MPMoviePlayerController实例叫做moviePlayer);
moviePlayer.currentPlaybackTime = moviePlayer.duration;[moviePlayer stop];| 归档时间: |
|
| 查看次数: |
2343 次 |
| 最近记录: |