首先是关于应用程序的一些背景...
- 有很多繁重的 UI 操作涉及视频播放器(主要是滚动)
- 视频是动态的,并且根据我们当前的页面而变化。
- 所以视频必须是动态的并不断变化,用户界面也需要响应
我最初使用的是 aMPMoviePlayerController
但由于某些要求我不得不依靠 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 真的没有响应且丑陋,而且此操作无法在后台执行
有什么解决方法或解决方法吗..?