ios知道hls livestream何时播放最后一个区块
我对一个流没有问题,但我不知道它何时缓冲或流何时结束。在Objective-C中是否有确定的方法。我已经找到了音频解决方案,我甚至尝试了AVPlayerItemDidPlayToEndTimeNotification,但它不起作用。有什么建议吗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
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