【问题标题】:ios Knowing when a hls livestream has played the last chunkios 知道 hls 直播何时播放了最后一个块
【发布时间】:2017-11-09 12:20:26
【问题描述】:

我对流没有问题,但我不知道它何时缓冲或流何时结束。无论如何在Objective-C中确定这一点。我找到了音频解决方案,我什至尝试了 AVPlayerItemDidPlayToEndTimeNotification 但它不起作用。有什么建议?

    NSString *url = liveStream.stream[@"cdn"];

    dispatch_async(dispatch_get_main_queue(), ^{
        AVPlayerItem *playerItem = [[AVPlayerItem alloc]
                                    initWithURL:[NSURL URLWithString:url]];
         [_player replaceCurrentItemWithPlayerItem:playerItem];


        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(itemDidFinishPlaying:) name:AVPlayerItemDidPlayToEndTimeNotification object:playerItem];



        [_player play];
    });
}

-(void)itemDidFinishPlaying:(NSNotification *) notification {

}

【问题讨论】:

    标签: ios objective-c avplayer http-live-streaming


    【解决方案1】:

    除了你正在使用的通知,你应该使用KVO来观察avPlayer的速率,以及avplayer当前AVPlayer项的状态。通过观察这些属性,您可以创建一个状态机,让您的播放器视图控制器知道发生了什么,并且可以从各种状态变化中恢复。根据您观察到的属性,您必须准备和恢复各种玩家状态。

    Here's an answer on how to check for buffering

    Here's an example of a complete AVPLayer

    And of course, here's apple's documentation on AVPlayer

    Here's the documentation on AVPlayerItem

    Lastly, here's the link on KVOController. You'll thank me for this later.

    【讨论】:

    • 谢谢@StevenOjo
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-02-12
    • 1970-01-01
    • 2020-05-15
    • 1970-01-01
    • 1970-01-01
    • 2018-11-17
    • 1970-01-01
    相关资源
    最近更新 更多