我对流没有问题,但我不知道它何时缓冲或流何时结束。无论如何在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 item 的状态。通过观察这些属性,你可以创建一个状态机,让你的玩家视图控制器知道发生了什么,并且可以从各种状态变化中恢复。您必须根据观察到的属性为各种玩家状态做好准备并从中恢复。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句