【问题标题】:Streaming video over HTTP in IOS在 IOS 中通过 HTTP 流式传输视频
【发布时间】:2012-07-16 06:46:07
【问题描述】:

我正在开发我的应用程序。它需要通过服务器在 iPhone 上播放视频。我有一个视频链接http://www.cwtmedia.se/cwtvideo.mp4。任何人都可以建议我如何在 MPMoviePlayerController 上执行此操作。我正在使用此代码,但它不起作用。

enter code here


NSURL *url = [NSURL fileURLWithPath:@"http://www.cwtmedia.se/cwtvideo.mp4"];
moviePlayer1 = [[MPMoviePlayerController alloc] initWithContentURL:url];
[self.view addSubview:moviePlayer1.view];
moviePlayer1.view.frame = CGRectMake(0, 0, 320, 416); 
moviePlayer1.fullscreen=YES;
[moviePlayer1 setFullscreen:NO animated:YES];
moviePlayer1.controlStyle = MPMovieControlStyleFullscreen;

[moviePlayer1 play];

【问题讨论】:

标签: iphone ios


【解决方案1】:

顺便说一下,这是我使用 mpmovieplayercontroller 进行流式传输的方式:

NSURL *url = [NSURL URLWithString:videoUrl];
moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
[moviePlayer setControlStyle:MPMovieControlStyleDefault];
moviePlayer.scalingMode = MPMovieScalingModeAspectFit;
CGRect frame;
if(self.interfaceOrientation ==UIInterfaceOrientationPortrait)
    frame = CGRectMake(20, 69, 280, 170);
else if(self.interfaceOrientation ==UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation ==UIInterfaceOrientationLandscapeRight)
    frame = CGRectMake(20, 61, 210, 170);
[moviePlayer.view setFrame:frame];  // player's frame must match parent's
[self.view addSubview: moviePlayer.view];
[self.view bringSubviewToFront:moviePlayer.view];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayBackDidFinish:)
                                             name:MPMoviePlayerPlaybackDidFinishNotification
                                           object:moviePlayer];

[moviePlayer prepareToPlay];
[moviePlayer play];

然后是委托方法:

- (void) moviePlayBackDidFinish:(NSNotification*)notification {
       MPMoviePlayerController *player = [notification object];
       [[NSNotificationCenter defaultCenter] 
            removeObserver:self
            name:MPMoviePlayerPlaybackDidFinishNotification
            object:player];

       if ([player respondsToSelector:@selector(setFullscreen:animated:)]){
          //self.navigationController.navigationBarHidden = YES;
          [player.view removeFromSuperview];
       }
}

希望这会对你有所帮助..

【讨论】:

    【解决方案2】:

    据我所知,您有两种选择:

    1) 首先下载文件并在本地播放。像这样:

       NSString *url = [[NSBundle mainBundle] pathForResource:@"cwtvideo" ofType:@"mp4"];
       MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL fileURLWithPath:url]];
    

    2) 使用 HTTP 流协议。据我所知,HTTP streaming 是 MPMoviePlayerController 已知的唯一流媒体协议。

    希望这会有所帮助。

    干杯!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-04-25
      • 1970-01-01
      • 2019-01-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-19
      相关资源
      最近更新 更多