rx-player
Version:
Canal+ HTML5 Video Player
67 lines (66 loc) • 2.06 kB
JavaScript
;
/**
* Copyright 2015 CANAL+ Group
*
* 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.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.default = removeCue;
var log_1 = require("../log");
var env_detector_1 = require("./env_detector");
/**
* Return true if given cue is active.
* @param {TextTrack} track
* @param {TextTrackCue} cue
* @returns {boolean}
*/
function isActiveCue(track, cue) {
var activeCues = track.activeCues;
if (activeCues === null) {
return false;
}
for (var i = 0; i < activeCues.length; i++) {
if (activeCues[i] === cue) {
return true;
}
}
return false;
}
/**
* Remove cue from text track.
* @param {TextTrack} track
* @param {TextTrackCue} cue
*/
function removeCue(track, cue) {
// On Firefox, cue doesn't dissapear when it is removed from track. Track
// should be hidden, and shown again after removing cue, in order to
// definitely clean the cue.
if (env_detector_1.default.browser === env_detector_1.default.BROWSERS.Firefox && isActiveCue(track, cue)) {
var trackMode = track.mode;
track.mode = "hidden";
try {
track.removeCue(cue);
}
catch (_err) {
log_1.default.warn("text", "Could not remove cue from text track.");
}
track.mode = trackMode;
return;
}
try {
track.removeCue(cue);
}
catch (_err) {
log_1.default.warn("text", "Could not remove cue from text track.");
}
}