0

我正在尝试使用 MPMoviePlayerController 通过 HTTP Live Streaming(使用 Adob​​e Media Server)播放视频。

- (void) viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self playVideo];
}

- (void) playVideo{
    NSURL *url = [NSURL URLWithString:@"http://192.168.10.27/hls-vod/test.mp4.m3u8"];
    MPMoviePlayerController *moviePlayer =
    [[MPMoviePlayerController alloc] initWithContentURL:url];
    moviePlayer.controlStyle = MPMovieControlStyleDefault;
    [self.view addSubview:moviePlayer.view];
    [moviePlayer setFullscreen:YES animated:YES];
    [moviePlayer play];
}

播放器正常启动,但仍在加载且未开始播放视频。我在我的设备下的 Safari 上尝试了一些链接,它可以正常工作!

你对这个问题有什么想法吗?

4

3 回答 3

3

我找到了解决方案!我只需要在控制器的界面中声明 moviePlayer 并启动它的 playVideo 方法就可以了!

于 2013-02-01T23:52:20.527 回答
0
  1. 您是否在真实设备上尝试过?有时 MPMoviePlayerControllers 无法在模拟器中正常播放。

  2. 您是否一次创建多个 MPMoviePlayerController?您只能实例化一个 MPMoviePlayerController,因此如果您需要播放第二个视频,则必须销毁或重用第一个视频。

  3. 文件是播放列表,而m3u8不是视频文件,因此请查看文件并确保它指向 MPMoviePlayerController 支持的文件类型。

另外:请注意,您正在 viewDidAppear 方法中播放视频。请注意,任何时候用户在 MPMoviePlayerController 上退出全屏时都会调用它,因此您可能希望在此处包含更多逻辑来决定是否显示它。(除非你总是想永远展示它。)

于 2013-01-31T17:18:44.947 回答
0

(固定的!!!!!)

我之前遇到过这个问题。

问题是由于静态播放器。尝试使用 MPMoviewPlayer 的属性

示例代码如下所示:

@interface YourViewController ()
@property (nonatomic, strong) MPMoviewPlayer *mp;
@end

@implementation YourViewController
- (void)playVideo {
    NSURL *movieURL = [NSURL URLWithString:@"http://the/url/playlist.m3u8"];
    self.mp = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];

    if (self.mp)
    {
        self.mp.view.frame = self.view.bounds;
        [self.view addSubview:self.mp.view];

        // save the movie player object
        [self.mp setFullscreen:YES];

        // Play the movie!
        [self.mp play];
    }
}

@end
于 2015-06-25T09:34:45.997 回答