大佬教程收集整理的这篇文章主要介绍了iphone – AVPlayerItem replaceCurrentItemWithPlayerItem Blocking,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我最初使用的是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 *asset = [AVAsset assetWithURL:self.mediaURL]; [asset loadValuesAsynchronouslyForKeys:@[@"duration"] completionHandler:^{ AVPlayerItem *newItem = [[AVPlayerItem alloc] initWithAsset:asset]; [self.avPlayer replaceCurrentItemWithPlayerItem:newItem]; }];
在我的情况下,URL是@L_944_0@网络资源,并且replaceCurrentItemWithPlayerItem:实际上将阻塞几秒等待此信息下载否则。
以上是大佬教程为你收集整理的iphone – AVPlayerItem replaceCurrentItemWithPlayerItem Blocking全部内容,希望文章能够帮你解决iphone – AVPlayerItem replaceCurrentItemWithPlayerItem Blocking所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。