Question

I'm generating a list of available audio tracks when an HLS stream is ready to play. I can access the available audio tracks just fine, but I'm having difficulty extracting the correct 'Title' for each track.

I'm using Apple's test stream which has two audio tracks. I extract the tracks with this...

availableAudioTrackList = [[NSMutableArray alloc] init];
AVMediaSelectionGroup *audioTracks = [player.currentItem.asset mediaSelectionGroupForMediaCharacteristic:AVMediaCharacteristicAudible];
for (int i = 0; i < [audioTracks.options count]; i++) {
    AVMediaSelectionOption *opt = audioTracks.options[i];
    NSLog(@"Opt: %@", opt);
    [availableAudioTrackList insertObject:opt.displayName atIndex:i];
}
NSLog(@"Audio Track Array: %@", availableAudioTrackList);

My output shows that 'opt.displayName' does not give the title of BipBop Audio 1 and BipBop Audio 2 (these are the distinguishing names I want to be able to use).

... Opt: <AVMediaSelectionKeyValueOption: 0x15dad0d0, locale = en, mediaType = 'soun', title = BipBop Audio 1, default = YES> 
... Opt: <AVMediaSelectionKeyValueOption: 0x15dad100, locale = en, mediaType = 'soun', title = BipBop Audio 2>

...Audio Track Array: ( English, English )

Any idea how/if I can extract the title from the AVMediaSelectionOption object?

Thanks!

Was it helpful?

Solution

You have to fetch it from metadata as follows

    NSArray *metaDatas = [AVMetadataItem metadataItemsFromArray:opt.commonMetadata withKey:@"title" keySpace:@"comn"];
    if (metaDatas.count > 0) {
      NSString *title = ((AVMetadataItem*)[metaDatas objectAtIndex:0]).stringValue;
      NSLog(@"title: %@", title);
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top