Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ios知道hls livestream何时播放最后一个区块_Ios_Objective C_Avplayer_Http Live Streaming - Fatal编程技术网

ios知道hls livestream何时播放最后一个区块

ios知道hls livestream何时播放最后一个区块,ios,objective-c,avplayer,http-live-streaming,Ios,Objective C,Avplayer,Http Live Streaming,我对一个流没有问题,但我不知道它何时缓冲或流何时结束。在Objective-C中是否有确定的方法。我已经找到了音频解决方案,我甚至尝试了AVPlayerItemDidPlayToEndTimeNotification,但它不起作用。有什么建议吗 NSString *url = liveStream.stream[@"cdn"]; dispatch_async(dispatch_get_main_queue(), ^{ AVPlayerItem *playerIt

我对一个流没有问题,但我不知道它何时缓冲或流何时结束。在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 {

}

除了您正在使用的通知之外,您还应该使用KVO来观察avPlayer的速率,以及avPlayer当前avPlayer项目的状态。通过观察这些属性,您可以创建某种状态机,使您的播放器视图控制器知道发生了什么,并且可以从各种更改中恢复。根据您观察到的属性,您必须准备和恢复不同的玩家状态


谢谢@StevenOjo