HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iphone – AVPlayerItem replaceCurrentItemWithPlayerItem Blocking大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
关于应用程序的第@L_944_0@上下文…
  – 有很多UI操作涉及视频播放器(主要是滚动)
  – 视频是动态的,根据我们当前的页面进行更改。
  – 所以视频必须是动态的,不断变化,UI也需要响应

我最初使用的是MPMoviePlayerController,但是由于某些要求我不得不回到AVPlayer上
我为AVPlayer制作了自己的包装。
要更改videoPlayer中的内容,这是AVPlayer-wrapper类中的方法

/**We need to change the whole playerItem each time we wish to change a video url */
-(void)initializePlayerWithUrl:(NSURL *)url
{
    AVPlayerItem *tempItem = [AVPlayerItem playerItemWithURL:url];

    [tempItem addObserver:self forKeyPath:@"status"
                  options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
                  context:nil];
    [tempItem addObserver:self forKeyPath:@"playBACkBufferEmpty"
                  options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
                  context:nil];

    //Not sure if this should be stopped or paused under the ideal circumstances
    //these will be changed to custom enums later
    [self setPlayBACkState:MPMoviePlayBACkStateStopped];
    [self setLoadState:MPMovieLoadStateUnkNown];
    [self.videoPlayer replaceCurrentItemWithPlayerItem:tempItem];

    //This is required only if we wish to pause the video immediately as we change the url
    //[self.videoPlayer pause];
}

现在的一切都很正常……除了..

[self.videoPlayer replaceCurrentItemWithPlayerItem:tempItem];

似乎阻止UI几分之一秒,在滚动这些使UI真的没有反应和丑陋的这个操作不能在后台执行

这有什么修复或解决方法吗?

解决方法

我发现的解决方案是确保底层的AVAsset准备好返回基本信息,如其持续时间,然后再将其提供给AVPlayer。 AVAsset有@L_944_0@方法loadValuesAsynchronouslyForKeys:这是方便的:

AVAsset *asset = [AVAsset assetWithURL:self.mediaURL];
[asset loadValuesAsynchronouslyForKeys:@[@"duration"] completionHandler:^{
    AVPlayerItem *newItem = [[AVPlayerItem alloc] initWithAsset:asset];
    [self.avPlayer replaceCurrentItemWithPlayerItem:newItem];
}];

在我的情况下,URL是@L_944_0@网络资源,并且replaceCurrentItemWithPlayerItem:实际上将阻塞几秒等待此信息下载否则。

@H_403_47@

大佬总结

以上是大佬教程为你收集整理的iphone – AVPlayerItem replaceCurrentItemWithPlayerItem Blocking全部内容,希望文章能够帮你解决iphone – AVPlayerItem replaceCurrentItemWithPlayerItem Blocking所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。