add: role ForcedSubtitle, useful for filtering (#574)

see also https://github.com/google/ExoPlayer/issues/9727
This commit is contained in:
lollolong 2024-12-29 14:45:24 +01:00 committed by GitHub
parent f47a0722cf
commit cd4dfb5e75
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 18 additions and 2 deletions

View File

@ -11,4 +11,5 @@ public enum RoleType
Description = 6,
Sign = 7,
Metadata = 8,
ForcedSubtitle = 9
}

View File

@ -178,8 +178,8 @@ internal partial class DASHExtractor2 : IExtractor
var role = representation.Elements().FirstOrDefault(e => e.Name.LocalName == "Role") ?? adaptationSet.Elements().FirstOrDefault(e => e.Name.LocalName == "Role");
if (role != null)
{
var v = role.Attribute("value")?.Value;
if (Enum.TryParse(v, true, out RoleType roleType))
var roleValue = role.Attribute("value")?.Value;
if (Enum.TryParse(roleValue, true, out RoleType roleType))
{
streamSpec.Role = roleType;
@ -190,6 +190,21 @@ internal partial class DASHExtractor2 : IExtractor
streamSpec.Extension = "ttml";
}
}
else if (roleValue != null && roleValue.Contains('-'))
{
roleValue = roleValue.Replace("-", "");
if (Enum.TryParse(roleValue, true, out RoleType roleType_))
{
streamSpec.Role = roleType_;
if (roleType_ == RoleType.ForcedSubtitle)
{
streamSpec.MediaType = MediaType.SUBTITLES; // or maybe MediaType.CLOSED_CAPTIONS?
if (mType != null && mType.Contains("ttml"))
streamSpec.Extension = "ttml";
}
}
}
}
streamSpec.Playlist.IsLive = isLive;
// 设置刷新间隔 timeShiftBufferDepth / 2