Ios 如何替换MPMoviePlayer通知?
在iOS 9中,MPMoviePlayer及其所有组件都已弃用。 我们使用MPMoviePlayerController通知,如Ios 如何替换MPMoviePlayer通知?,ios,mpmovieplayercontroller,ios9,avplayer,avplayerviewcontroller,Ios,Mpmovieplayercontroller,Ios9,Avplayer,Avplayerviewcontroller,在iOS 9中,MPMoviePlayer及其所有组件都已弃用。 我们使用MPMoviePlayerController通知,如MPMoviePlayerLoadStateDidChangeNotification、MPMovieDurationAvailableNotification、MPMoviePlayerPlayerBackstateDidChangeNotification、MPMoviePlayerReadyFordDisplayDidChangeNotification,跟踪视频
MPMoviePlayerLoadStateDidChangeNotification、MPMovieDurationAvailableNotification、MPMoviePlayerPlayerBackstateDidChangeNotification、MPMoviePlayerReadyFordDisplayDidChangeNotification
,跟踪视频服务质量。但是现在使用avplayervewcontroller,我无法找到这些通知的正确替代品
现在如何替换这些通知?我查看了
MPMoviePlayerNotifications
和AVPlayerItemNotifications
的文档,注意到两件事
所以,我很困惑,你是说
MPMoviePlayerNotifications
被弃用了,因为文档说它们是可用的。另外,我不认为AVPlayerItemNotifications
替代了MPMoviePlayerNotifications
avplayervewcontroller
在用法上与mpmovieplayervewcontroller
有很大不同。不使用通知,而是使用键值观察来确定与avplayervewcontroller
关联的AVPlayer
对象的当前特征。根据文件:
您可以使用键值观察来观察玩家的状态。所以
AVPlayer可以安全地添加和删除观察者
在服务器上播放期间动态发生的更改通知
调度队列。默认情况下,此队列是主队列(请参见
调度(获取主队列)。确保安全访问玩家的
播放状态中的动态变化可能是非原子属性
报告,则必须使用接收方的通知序列化访问
队列在一般情况下,这种序列化自然是通过
在主线程或队列上调用AVPlayer的各种方法
例如,如果您想知道播放机何时暂停,请在AVPlayer
对象的rate
属性上添加观察者:
[self.player addObserver:self forKeyPath:@"rate" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld context: &PlayerRateContext];
然后在观察方法中检查新值是否等于零:
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context {
if (context == &PlayerRateContext) {
if ([[change valueForKey:@"new"] integerValue] == 0) {
// summon Sauron here (or whatever you want to do)
}
return;
}
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
return;
}
-(void)observeValueForKeyPath:(NSString*)对象的键路径:(id)对象更改:(NSDictionary*)更改上下文:(void*)上下文{
if(上下文==&PlayerRateContext){
如果([[change valueForKey:@“new”]integerValue]==0){
//在这里召唤索伦(或者你想做的任何事情)
}
返回;
}
[super observeValueForKeyPath:对象的关键路径:对象更改:更改上下文:上下文];
返回;
}
AVPlayer
上的许多属性都是可见的。通过检查
除此之外,还有一些可用于AVPlayerItem
对象的通知,这些通知虽然有限,但仍然有用
通知
AvPlayerItemDidPlayToEndTime通知
AvPlayerItemFailedToLaytoEndTime通知
AVPlayerItemTimeJumpedNotification
AvplayerTemplate后台通知
AVPlayerItemNewAccessLogEntryNotification
AVPlayerItemNewErrorLogEntryNotification
我发现avplayerietemdidplaytoendtimenotification
在播放结束后查找开始项时特别有用
将这两个选项结合使用,您应该能够替换MPMoviePlayerController
文档中的大部分通知:在iOS 9中,MPMoviePlayerController类被正式弃用。(MPMoviePlayerController类也被正式弃用。)若要在iOS 9及更高版本中播放视频内容,请改用AVKit框架中的AVPictureInPictureController或AVPlayerServiceController类,或WebKit中的WKWebView类
。我想,这意味着将来不会有MPMoviePlayerNotifications
通知。您还可以提供JWPlayer通知列表吗?无法在网上找到简明列表。如何在AVPlayer中转换MPMoviePlayerPlayerPlayerBackstateDidChangeNotification?