如何从服务器流式传输视频到iPad?
问题描述:
我正在从服务器将视频流入我的iPad应用程序。我使用下面的代码:如何从服务器流式传输视频到iPad?
NSURL *videoURL = [NSURL URLWithString:@"http://10.1.0.251/blah/videos/test.mp4"];
MPMoviePlayerViewController* playerController = [[MPMoviePlayerViewController alloc] initWithContentURL:videoURL];
playerController.moviePlayer.view.frame = CGRectMake(50, 50, 200, 200);
[self presentMoviePlayerViewControllerAnimated:playerController];
playerController.moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
[playerController.moviePlayer play];
[playerController release];
playerController=nil;
这使我在帧视频没有控制能力,并播放视频一次之后,玩家退出?我如何控制框架并允许“重播”?
下面的代码可以让我在iPhone和还对iPad的(本地视频只不是流)
NSURL *url = [NSURL URLWithString:strVideo];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
moviePlayer.view.frame = CGRectMake(50, 50, 480, 320);
moviePlayer.movieSourceType = MPMovieSourceTypeStreaming;
moviePlayer.scalingMode=MPMovieScalingModeAspectFill;
moviePlayer.shouldAutoplay = YES;
moviePlayer.controlStyle=MPMovieControlStyleEmbedded;
[self.view addSubview:moviePlayer.view];
[moviePlayer play];
如何实现为iPad相同的上述功能?
答
好吧,上述定制不能在ipad中实现。 MPMoviePlayerController或MPMoviePlayerViewController不允许。
那些需要这样的自定义关闭按钮,我使用的解决方法是通过UIWebView播放视频,并有这样的关闭按钮。不优雅,但做的工作。
编辑:如果您需要对本地播放的视频执行相同操作,则可以通过MPMoviePlayerController实现。
答
虽然它的数据来自网络,它的数据类型是文件。所以,修改下面的代码:
playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;