Unverified Commit a26dc264 authored by Hampton Maxwell's avatar Hampton Maxwell Committed by GitHub
Browse files

Bypass cache when sideloaded text tracks are specified

Fixes a crash when using the cache & sideloaded text tracks together due to the tracks on the asset not being available. Re-visit when someone with more expertise on the cache can look at it.
parent 86d655c3
Loading
Loading
Loading
Loading
+12 −8
Changes for ios/Video/RCTVideo.m: 12 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -382,11 +382,6 @@ static int const RCTVideoUnset = -1;

- (void)playerItemPrepareText:(AVAsset *)asset assetOptions:(NSDictionary * __nullable)assetOptions withCallback:(void(^)(AVPlayerItem *))handler
{
  if (!_textTracks) {
    handler([AVPlayerItem playerItemWithAsset:asset]);
    return;
  }

  // sideload text tracks
  AVMutableComposition *mixComposition = [[AVMutableComposition alloc] init];
  
@@ -454,7 +449,16 @@ static int const RCTVideoUnset = -1;
      NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies];
      [assetOptions setObject:cookies forKey:AVURLAssetHTTPCookiesKey];
#if __has_include(<react-native-video/RCTVideoCache.h>)
      if (_textTracks) {
        /* The DVURLAsset created by cache doesn't have a tracksWithMediaType property, so trying
         * to bring in the text track code will crash. I suspect this is because the asset hasn't fully loaded.
         * Until this is fixed, we need to bypass caching when text tracks are specified.
         */
        AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:assetOptions];
        [self playerItemPrepareText:asset assetOptions:assetOptions withCallback:handler];
      } else {
        [self playerItemForSourceUsingCache:uri assetOptions:assetOptions withCallback:handler];
      }
#else
      AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:assetOptions];
      [self playerItemPrepareText:asset assetOptions:assetOptions withCallback:handler];
@@ -496,19 +500,19 @@ static int const RCTVideoUnset = -1;
                }
        }

        /*
        DVURLAsset *asset = [[DVURLAsset alloc] initWithURL:url options:options networkTimeout:10000];
        asset.loaderDelegate = self;
         */
        
        /* More granular code to 
        DVAssetLoaderDelegate *resourceLoaderDelegate = [[DVAssetLoaderDelegate alloc] initWithURL:url];
        resourceLoaderDelegate.delegate = self;
        NSURLComponents *components = [[NSURLComponents alloc] initWithURL:url resolvingAgainstBaseURL:NO];
        components.scheme = [DVAssetLoaderDelegate scheme];
        AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[components URL] options:options];
        [asset.resourceLoader setDelegate:resourceLoaderDelegate queue:dispatch_get_main_queue()];
        */

        [self playerItemPrepareText:asset assetOptions:options withCallback:handler];
        handler([AVPlayerItem playerItemWithAsset:asset]);
    }];
}