Reloading keys in AVAsset when status is AVKeyValueStatusFailed

匿名 (未验证) 提交于 2019-12-03 08:48:34

问题:

I'm doing the following:

  • 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 calling loadValuesAsynchronouslyForKeys: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.

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?

回答1:

  1. Are you creating a new AVURLAsset or just reusing the previous one?
  2. 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];              });          }];     } }


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!