如何从服务器将视频流式传输到iPad?

时间:2011-02-17 15:43:14

标签: ios4 video-streaming ipad mpmovieplayercontroller

我正在从服务器将视频流式传输到我的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实现相同目标?

2 个答案:

答案 0 :(得分:1)

虽然它的数据来自网络,但它的数据类型是文件。因此,请修改以下代码:

playerController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;

答案 1 :(得分:0)

好的,上面的定制无法在ipad中实现。 MPMoviePlayerController或MPMoviePlayerViewController不允许这样做。

那些需要这种自定义关闭按钮的人,我使用的解决方法是通过UIWebView播放视频并在其上设置如此紧密的按钮。不优雅,但做的工作。

编辑:如果您需要对本地播放的视频执行相同操作,则可以通过MPMoviePlayerController实现。