-(void)playVideo:(NSURL *)url{
if (videoPlayer) {
[videoPlayer release];
videoPlayer = nil;
}
videoPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
url = nil;
videoPlayer.moviePlayer.controlStyle=MPMovieControlStyleFullscreen;
videoPlayer.view.autoresizingMask = (UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight);
videoPlayer.moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
videoPlayer.view.backgroundColor = [UIColor blackColor];
[[UIApplication sharedApplication]
setStatusBarStyle:UIStatusBarStyleBlackTranslucent animated:NO];
[videoPlayer.moviePlayer prepareToPlay];
videoPlayer.moviePlayer.shouldAutoplay = YES;
videoPlayer.hidesBottomBarWhenPushed = YES;
self.navigationController.navigationBarHidden=NO;
videoPlayer.navigationItem.hidesBackButton = YES;
[self.navigationController pushViewController:videoPlayer animated:YES];
[self addObservers];
}
有谁可以说这段代码有什么问题?网址是流式传输http链接。视频播放器正在出现但过了一段时间它就消失了。它在3G网络中工作但不在wifi中
答案 0 :(得分:1)
正如你所说它在3G网络上而不是在WiFi网络上工作时,你的问题很可能与代码无关,而是与你正在测试的电影文件有关。
确保m3u8-snippet完整且对低带宽也有效。按照此Best Practice Guide和此TechNote的说明,使用Apples Mediastream Validator测试m3u8。
答案 1 :(得分:-1)
这一行之后:
videoPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
添加:
[videoPlayer retain];