首先关于应用一点背景知识...
- 有很多的重型UI操作的包括视频播放器(主要是滚动)
- 这些视频基于我们当前的页面是动态的,变化的。
- 让视频的必须是动态的,不断变化,也是UI需要响应
我最初使用MPMoviePlayerController
但随后由于有一定的要求,我不得不求助于AVPlayer
我做了我自己的包装为AVPlayer
。
要在录像机这一变化的内容是什么方法看起来像在AVPlayer,包装类
/**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];
}
现在,ofcourse一切工作正常......除了..
[self.videoPlayer replaceCurrentItemWithPlayerItem:tempItem];
似乎阻止了该UI用于几分之一秒和滚动这些期间使UI真的响应,并且也难看不能在后台执行该操作
有没有这方面的任何修订或变通方法..?