shaka-player
Version:
DASH/EME video player library
90 lines (75 loc) • 2.26 kB
JavaScript
/**
* @license
* Copyright 2016 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
goog.provide('shaka.hls.Utils');
goog.require('shaka.util.ManifestParserUtils');
/**
*
* @param {!Array.<!shaka.hls.Tag>} tags
* @param {!string} name
* @return {!Array.<!shaka.hls.Tag>}
*/
shaka.hls.Utils.filterTagsByName = function(tags, name) {
return tags.filter(function(tag) {
return tag.name == name;
});
};
/**
*
* @param {!Array.<!shaka.hls.Tag>} tags
* @param {!string} name
* @return {?shaka.hls.Tag}
*/
shaka.hls.Utils.getFirstTagWithName = function(tags, name) {
var tagsWithName = shaka.hls.Utils.filterTagsByName(tags, name);
if (!tagsWithName.length) return null;
return tagsWithName[0];
};
/**
* Expects an array of EXT-X-MEDIA tags. Returns the first tag that
* has given media type and group id.
*
* @param {!Array.<!shaka.hls.Tag>} tags
* @param {!string} type
* @param {!string} groupId
* @return {!Array<!shaka.hls.Tag>}
*/
shaka.hls.Utils.findMediaTags = function(tags, type, groupId) {
return tags.filter(function(tag) {
var typeAttr = tag.getAttribute('TYPE');
var groupIdAttr = tag.getAttribute('GROUP-ID');
return typeAttr.value == type && groupIdAttr.value == groupId;
});
};
/**
* @param {!string} parentAbsoluteUri
* @param {!string} uri
* @return {!string}
*/
shaka.hls.Utils.constructAbsoluteUri = function(parentAbsoluteUri, uri) {
var uris = shaka.util.ManifestParserUtils.resolveUris(
[parentAbsoluteUri], [uri]);
return uris[0];
};
/**
* Matches a string to an HLS comment format and returns the result.
*
* @param {!string} line
* @return {boolean}
*/
shaka.hls.Utils.isComment = function(line) {
return /^#(?!EXT)/m.test(line);
};