5

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?

4

1 回答 1

2
  1. 你是在创建一个新的 AVURLAsset 还是只是重用以前的?
  2. 在完成处理程序中,loadValuesAsynchronouslyForKeys:completionHandler:您是否将其分派回主线程?

如果您在准备重试时再次调用此方法(或类似的方法)会发生什么情况。

- (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];
             });
         }];
    }
}
于 2014-01-15T18:01:56.230 回答