【问题标题】:iOS: HTTP Live Streaming to app, Video won't playiOS:HTTP 实时流式传输到应用程序,视频不会播放
【发布时间】:2015-06-17 05:51:03
【问题描述】:

我有一些视频文件准备好在我的服务器上进行流式传输。这是我尝试在 iOS 应用中播放它们的代码:

    Video *vid = [videos objectAtIndex:index];
    NSURL *vidUrl = [NSURL URLWithString:vid.videoUrl];
    NSLog(@"%@",vid.videoUrl);
    MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:vidUrl];
    player.controlStyle=MPMovieControlStyleEmbedded;
    [player.view setFrame:self.view.bounds];
    [self.view addSubview:player.view];
    [player play];

如果我将 NSLog 吐出的 URL 复制并粘贴到 Safari 中,视频可以正常播放。所以我知道这个网址很好。但在我的应用程序中,我只是得到一个黑屏。我的代码有什么问题?

【问题讨论】:

    标签: ios media-player mpmovieplayercontroller http-live-streaming


    【解决方案1】:

    MPMoviePlayerController 需要是一个强属性,声明为@property (strong, nonatomic) MPMoviePlayerController *mvpc;

    那么每当你想播放一部电影时,你都会写:

    self.mvpc = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:@"movieURL"]];
    self.mvpc.shouldAutoplay = YES; //Optional
    self.mvpc.controlStyle = MPMovieControlStyleEmbedded;
    [self.mvpc prepareToPlay];
    [self.mvpc.view setFrame:self.view.bounds];
    [self.view addSubview:self.mvpc.view];
    [self.mvpc play];
    

    【讨论】:

    • 原因是MPMoviePlayerController需要保留,否则立即释放。由于系统内没有任何东西保留它,因此您必须自己做。为了保留它,你可以在你的类中建立一个强大的属性/实例,涵盖该工作。
    • 感谢Till,感谢您的解释。
    猜你喜欢
    • 2016-12-03
    • 1970-01-01
    • 2014-09-27
    • 2022-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多