如何在 Objective-C 中访问 AVMediaSelectionKeyValueOption 的属性?

问题描述 投票:0回答:1

因此,我正在处理一个带有字幕轨道的视频,并且我正在尝试访问每个视频的名称和语言代码以显示在菜单中。目前我正在做:

AVMediaSelectionGroup *selectionGroup = [self.currentAsset mediaSelectionGroupForMediaCharacteristic:AVMediaCharacteristicLegible];
NSArray *subtitles = selectionGroup.options;
self.subtitlesOptions = [NSMutableArray arrayWithObject:@{ @"label": @"Off", @"value": @"off" }];

for(AVMediaSelectionOption *track in subtitles) {
    NSString *title = track.displayName; // This isn't right
    NSString *language = track.locale.localeIdentifier;
    [self.subtitlesOptions addObject:@{ @"label":title, @"value":language }];
}

当我打印每个

track
对象时,我会得到如下所示的内容。

<AVMediaSelectionKeyValueOption: 0x171c79c40, language = engcc, mediaType = 'sbtl', title = English Closed Captions>

我可以正确获取语言,但问题是

displayName
title
不相关,在这种情况下,它实际上返回“engcc”而不是“英语隐藏式字幕”。有什么办法可以得到
title
吗?

objective-c avplayer tvos
1个回答
-1
投票

我为您的问题找到了这个解决方案。工作正常。希望这会有所帮助。

for(AVMediaSelectionOption *track in subtitles) {
                NSString *language = nil;
                NSArray *contents = [AVMetadataItem metadataItemsFromArray:[mediaSelectionOption commonMetadata] withKey:AVMetadataCommonKeyTitle keySpace:AVMetadataKeySpaceCommon];
                if ([contents count] > 0)
                {

                    NSArray *titlesForPreferredLanguages = [AVMetadataItem metadataItemsFromArray:contents filteredAndSortedAccordingToPreferredLanguages:[NSLocale preferredLanguages]];
                    if ([titlesForPreferredLanguages count] > 0)
                    {
                        language = [[titlesForPreferredLanguages objectAtIndex:0] extendedLanguageTag];
                    }

                    if (language == nil)
                    {
                        language = [[contents objectAtIndex:0] extendedLanguageTag];
                    }
                }

    }
© www.soinside.com 2019 - 2024. All rights reserved.