Commit b6ee8f7f authored by Hampton Maxwell's avatar Hampton Maxwell
Browse files

Simplify text track + cache bypass code

parent a26dc264
Loading
Loading
Loading
Loading
+13 −8
Changes for ios/Video/RCTVideo.m: 13 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -382,6 +382,11 @@ 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];
  
@@ -448,21 +453,20 @@ 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) {
    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];
      return;
    }
#else
#endif

    AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:assetOptions];
    [self playerItemPrepareText:asset assetOptions:assetOptions withCallback:handler];
#endif
    return;
  } else if (isAsset) {
    AVURLAsset *asset = [AVURLAsset URLAssetWithURL:url options:nil];
@@ -495,7 +499,8 @@ static int const RCTVideoUnset = -1;
            default:
                if (cachedAsset) {
                    DebugLog(@"Playing back uri '%@' from cache", uri);
                    [self playerItemPrepareText:cachedAsset assetOptions:options withCallback:handler];
                    // See note in playerItemForSource about not being able to support text tracks & caching
                    handler([AVPlayerItem playerItemWithAsset:asset]);
                    return;
                }
        }
@@ -503,7 +508,7 @@ static int const RCTVideoUnset = -1;
        DVURLAsset *asset = [[DVURLAsset alloc] initWithURL:url options:options networkTimeout:10000];
        asset.loaderDelegate = self;
        
        /* More granular code to 
        /* More granular code to have control over the DVURLAsset
        DVAssetLoaderDelegate *resourceLoaderDelegate = [[DVAssetLoaderDelegate alloc] initWithURL:url];
        resourceLoaderDelegate.delegate = self;
        NSURLComponents *components = [[NSURLComponents alloc] initWithURL:url resolvingAgainstBaseURL:NO];