Skip to content

Instantly share code, notes, and snippets.

@megabayt
Created December 3, 2021 07:39
Show Gist options
  • Save megabayt/205b3e093e7c39e990458d4ae87cde3e to your computer and use it in GitHub Desktop.
Save megabayt/205b3e093e7c39e990458d4ae87cde3e to your computer and use it in GitHub Desktop.
AVURLAsset *textURLAsset;
NSString *textUri = [_textTracks objectAtIndex:i][@"uri"];
if ([[textUri lowercaseString] hasPrefix:@"http"]) {
textURLAsset = [AVURLAsset URLAssetWithURL:[NSURL URLWithString:textUri] options:assetOptions];
} else {
textURLAsset = [AVURLAsset URLAssetWithURL:[self urlFilePath:textUri] options:nil];
}
[textURLAsset loadValuesAsynchronouslyForKeys:@[@"playable",@"tracks"] completionHandler:^{
// Now tracks is available
NSLog(@" total tracks %@", textURLAsset.tracks);
NSError *error = nil;
AVKeyValueStatus status =
[textURLAsset statusOfValueForKey:@"tracks" error:&error];
switch (status) {
case AVKeyValueStatusLoaded:
NSLog(@"AVKeyValueStatusLoaded");
break;
case AVKeyValueStatusFailed:
NSLog(@"AVKeyValueStatusFailed");
break;
case AVKeyValueStatusCancelled:
NSLog(@"AVKeyValueStatusCancelled");
break;
default:
NSLog(@"default");
break;
}
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment