【问题标题】:Issue while streaming video from server从服务器流式传输视频时出现问题
【发布时间】:2013-12-24 11:19:34
【问题描述】:

我在服务器上有一个视频文件。当我复制 URL 并在 safari 中运行时,它开始使用快速播放器在浏览器中播放视频,但它没有在模拟器中播放,它显示正在加载但没有任何反应。请帮我。我该如何解决这个问题?

谢谢。

-

(void)playMovieWithUrl:(NSString*)url{
    moviePlayerViewController = [[MPMoviePlayerViewController alloc] init];
    moviePlayerViewController.moviePlayer.controlStyle = MPMovieControlStyleDefault;

    moviePlayerViewController.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight |
    UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin |
    UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
    [self.view addSubview:moviePlayerViewController.moviePlayer.view];
   [moviePlayerViewController.moviePlayer setFullscreen:YES];

   [moviePlayerViewController.moviePlayer stop];
    NSLog(@"playerUrl %@",url);
    [moviePlayerViewController.moviePlayer setMovieSourceType:MPMovieSourceTypeStreaming];
    [moviePlayerViewController.moviePlayer setContentURL:[NSURL URLWithString:url]];
    [moviePlayerViewController.moviePlayer prepareToPlay];
    //moviePlayerViewController.moviePlayer.initialPlaybackTime = interval;
    [moviePlayerViewController.moviePlayer play];

}

【问题讨论】:

  • 视频文件的扩展名?
  • 视频文件为mp4类型
  • 移除[moviePlayerViewController.movi​​ePlayer stop];并添加观察者 [[NSNotificationCenter defaultCenter] addObserver:self 选择器:@selector(moviePlayBackDidFinish:) name:MPMoviePlayerPlaybackDidFinishNotification object:moviePlayerViewController];并在“moviePlayBackDidFinish”方法中释放控制器并删除像 [moviePlayerViewController autorelease] 这样的观察者;电影播放器​​视图控制器 = 无; [[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:nil];
  • 你也可以使用 UIWebView

标签: ios iphone objective-c mpmovieplayercontroller movieplayer


【解决方案1】:

这对我有用:

NSURL *streamURL = [NSURL URLWithString:@"http://www.nasa.gov/multimedia/nasatv/NTV-Public-IPS.m3u8"];
_streamPlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:streamURL];
[_streamPlayer.view setFrame:self.view.bounds];
[self.view addSubview:_streamPlayer.view];
[_streamPlayer.moviePlayer play];

_streamPlayer 声明为:

@property (strong, nonatomic) MPMoviePlayerViewController *streamPlayer;

请注意,我正在添加 MPMoviePlayerViewController 的视图,而您正在添加 moviePlayer.view

【讨论】:

  • OP 代码失败的原因是使用了 ARC(如副本所示),它立即释放了播放器。我强烈反对在自定义视图堆栈中使用MPMoviePlayerViewController,但仅使用MPMoviePlayerControllerMPMoviePlayerViewController 仅用于全屏播放!
猜你喜欢
  • 1970-01-01
  • 2019-02-25
  • 2011-01-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-26
  • 2012-10-02
相关资源
最近更新 更多