mirror of
https://github.com/samsonjs/media.git
synced 2026-04-09 11:55:46 +00:00
Parse NAME label from HLS Master Playlist
The HlsPlaylistParser now parses the "NAME" property from the MasterHlsPlaylist and saves it in the Variant
This commit is contained in:
parent
5b81612c3b
commit
eb282639c5
3 changed files with 10 additions and 4 deletions
|
|
@ -184,7 +184,7 @@ public class HlsChunkSource {
|
|||
playlistParser = new HlsPlaylistParser();
|
||||
|
||||
if (playlist.type == HlsPlaylist.TYPE_MEDIA) {
|
||||
variants = new Variant[] {new Variant(0, playlistUrl, 0, null, -1, -1)};
|
||||
variants = new Variant[] {new Variant(0, null, playlistUrl, 0, null, -1, -1)};
|
||||
variantPlaylists = new HlsMediaPlaylist[1];
|
||||
variantLastPlaylistLoadTimesMs = new long[1];
|
||||
variantBlacklistTimes = new long[1];
|
||||
|
|
|
|||
|
|
@ -143,6 +143,7 @@ public final class HlsPlaylistParser implements UriLoadable.Parser<HlsPlaylist>
|
|||
String codecs = null;
|
||||
int width = -1;
|
||||
int height = -1;
|
||||
String name = null;
|
||||
|
||||
boolean expectingStreamInfUrl = false;
|
||||
String line;
|
||||
|
|
@ -152,18 +153,20 @@ public final class HlsPlaylistParser implements UriLoadable.Parser<HlsPlaylist>
|
|||
String type = HlsParserUtil.parseStringAttr(line, TYPE_ATTR_REGEX, TYPE_ATTR);
|
||||
if (SUBTITLES_TYPE.equals(type)) {
|
||||
// We assume all subtitles belong to the same group.
|
||||
String name = HlsParserUtil.parseStringAttr(line, NAME_ATTR_REGEX, NAME_ATTR);
|
||||
name = HlsParserUtil.parseStringAttr(line, NAME_ATTR_REGEX, NAME_ATTR);
|
||||
String uri = HlsParserUtil.parseStringAttr(line, URI_ATTR_REGEX, URI_ATTR);
|
||||
String language = HlsParserUtil.parseOptionalStringAttr(line, LANGUAGE_ATTR_REGEX);
|
||||
boolean isDefault = HlsParserUtil.parseOptionalBooleanAttr(line, DEFAULT_ATTR_REGEX);
|
||||
boolean autoSelect = HlsParserUtil.parseOptionalBooleanAttr(line, AUTOSELECT_ATTR_REGEX);
|
||||
subtitles.add(new Subtitle(name, uri, language, isDefault, autoSelect));
|
||||
name = null;
|
||||
} else {
|
||||
// TODO: Support other types of media tag.
|
||||
}
|
||||
} else if (line.startsWith(STREAM_INF_TAG)) {
|
||||
bitrate = HlsParserUtil.parseIntAttr(line, BANDWIDTH_ATTR_REGEX, BANDWIDTH_ATTR);
|
||||
codecs = HlsParserUtil.parseOptionalStringAttr(line, CODECS_ATTR_REGEX);
|
||||
name = HlsParserUtil.parseStringAttr(line, NAME_ATTR_REGEX, NAME_ATTR);
|
||||
String resolutionString = HlsParserUtil.parseOptionalStringAttr(line,
|
||||
RESOLUTION_ATTR_REGEX);
|
||||
if (resolutionString != null) {
|
||||
|
|
@ -184,9 +187,10 @@ public final class HlsPlaylistParser implements UriLoadable.Parser<HlsPlaylist>
|
|||
}
|
||||
expectingStreamInfUrl = true;
|
||||
} else if (!line.startsWith("#") && expectingStreamInfUrl) {
|
||||
variants.add(new Variant(variants.size(), line, bitrate, codecs, width, height));
|
||||
variants.add(new Variant(variants.size(), name, line, bitrate, codecs, width, height));
|
||||
bitrate = 0;
|
||||
codecs = null;
|
||||
name = null;
|
||||
width = -1;
|
||||
height = -1;
|
||||
expectingStreamInfUrl = false;
|
||||
|
|
|
|||
|
|
@ -26,9 +26,11 @@ public final class Variant implements FormatWrapper {
|
|||
|
||||
public final String url;
|
||||
public final Format format;
|
||||
public final String name;
|
||||
|
||||
public Variant(int index, String url, int bitrate, String codecs, int width, int height) {
|
||||
public Variant(int index, String name, String url, int bitrate, String codecs, int width, int height) {
|
||||
this.url = url;
|
||||
this.name = name;
|
||||
format = new Format(Integer.toString(index), MimeTypes.APPLICATION_M3U8, width, height, -1, -1,
|
||||
-1, bitrate, null, codecs);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue