Alternate audio tracks with HTTP Live Streaming

雨燕双飞 提交于 2020-01-14 17:11:09

问题


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!


回答1:


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);
    }


来源:https://stackoverflow.com/questions/19551399/alternate-audio-tracks-with-http-live-streaming

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!