当状态为AVKeyValueStatusFailed时,重新加载AVAsset中的键 [英] Reloading keys in AVAsset when status is AVKeyValueStatusFailed
问题描述
我正在执行以下操作:
- 创建一个新的
AVAsset
给定的URL。该URL指向远程Web服务器上的视频。 - 通过调用
尝试加载
track
属性loadValuesAsynchronouslyForKeys:completionHandler: - 初始请求失败,因为没有互联网连接
- 我注意到请求失败了调用
statusOfValueForKey:错误:
- 然后我等待连接重新出现(使用一些可达性代码)。一旦这样做,我再次调用
loadValuesAsynchronouslyForKeys:completionHandler:
。
- Create a new
AVAsset
with a given URL. That URL points to a video on a remote web server. - Attempt to load the
tracks
property by callingloadValuesAsynchronouslyForKeys:completionHandler:
- The initial request fails, because no internet connection exists
- I notice that the request failed by calling
statusOfValueForKey:error:
- I then wait for the connection to re-appear (using some reachability code). As soon as it does, I call
loadValuesAsynchronouslyForKeys:completionHandler:
again.
这是问题开始的地方。我会想象 AVAsset
继续尝试重新加载track属性,因为之前失败了。但是,这似乎不会发生。 statusOfValueForKey:错误:
仍将返回 AVKeyValueStatusFailed
,尽管有可用的互联网连接并且视频可播放。
Here's where the problems begin. I would imagine that the AVAsset
goes ahead and attempts to reload the tracks property since it failed previously. However, this does not seem to happen. statusOfValueForKey:error:
will still return AVKeyValueStatusFailed
, although a working internet connection is available and the video is playable.
有没有办法重置这个给定属性的状态并尝试另一个加载?还有另一种解决方法吗?
Is there a way to reset the state for this given property and to attempt another load? Is there another way to work around this?
推荐答案
- 您是在创建新的AVURLAsset还是只是重用上一个?
- 在
的完成处理程序中,loadValuesAsynchronouslyForKeys:completionHandler:
您是否已调度回主线程?
- Are you creating a new AVURLAsset or just reusing the previous one?
- In the completion handler for
loadValuesAsynchronouslyForKeys:completionHandler:
are you dispatching back to the main thread?
当你准备好重试时再次调用此方法(或类似的东西)会发生什么。
What happens if you call this method again (or something similar) when you're ready to retry.
- (void)setContentURL:(NSURL *)contentURL
{
if (_contentURL != contentURL) {
_contentURL = contentURL;
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:_contentURL options:nil];
NSArray *requestedKeys = [NSArray arrayWithObjects:ISIVideoPlayerControllerTracksKey, ISIVideoPlayerControllerPlayableKey, nil];
[asset loadValuesAsynchronouslyForKeys:requestedKeys completionHandler: ^{
dispatch_async(dispatch_get_main_queue(), ^{
[self prepareToPlayAsset:asset withKeys:requestedKeys];
});
}];
}
}
这篇关于当状态为AVKeyValueStatusFailed时,重新加载AVAsset中的键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!