Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x | import MediaPlayer from './MediaPlayer.js';
function MediaPlayerFactory() {
/**
* mime-type identifier for any source content to be accepted as a dash manifest by the create() method.
* @type {string}
*/
const SUPPORTED_MIME_TYPE = 'application/dash+xml';
let logger;
/**
* A new MediaPlayer is instantiated for the supplied videoElement and optional source and context. If no context is provided,
* a default DashContext is used. If no source is provided, the videoElement is interrogated to extract the first source whose
* type is application/dash+xml.
* The autoplay property of the videoElement is preserved. Any preload attribute is ignored. This method should be called after the page onLoad event is dispatched.
* @param {HTMLMediaElement} video
* @param {HTMLSourceElement} source
* @param {Object} context
* @returns {MediaPlayer|null}
*/
function create(video, source, context) {
if (!video || !(/^VIDEO$/i).test(video.nodeName)) {
return null;
}
if (video._dashjs_player) {
return video._dashjs_player;
}
let player;
let videoID = (video.id || video.name || 'video element');
source = source || [].slice.call(video.querySelectorAll('source')).filter(function (s) {
return s.type == SUPPORTED_MIME_TYPE;
})[0];
if (!source && video.src) {
source = document.createElement('source');
source.src = video.src;
} else if (!source && !video.src) {
return null;
}
context = context || {};
player = MediaPlayer(context).create();
player.initialize(video, source.src, video.autoplay);
if (!logger) {
logger = player.getDebug().getLogger();
}
logger.debug('Converted ' + videoID + ' to dash.js player and added content: ' + source.src);
// Store a reference to the player on the video element so it can be gotten at for debugging and so we know its
// already been setup.
video._dashjs_player = player;
return player;
}
/**
* Searches the provided scope for all instances of the indicated selector. If no scope is provided, document is used. If no selector is
* specified, [data-dashjs-player] is used. The declarative setup also looks for source elements with the type attribute set to 'application/dash+xml'.
* It then looks for those video elements which have a source element defined with a type matching 'application/dash+xml'.
* A new MediaPlayer is instantiated for each matching video element and the appropriate source is assigned.
* The autoplay property of the video element is preserved. Any preload attribute is ignored. This method should be called after the page onLoad event is dispatched.
* Returns an array holding all the MediaPlayer instances that were added by this method.
* @param {string} selector - CSS selector
* @param {Object} scope
* @returns {Array} an array of MediaPlayer objects
*/
function createAll(selector, scope) {
let aPlayers = [];
selector = selector || '[data-dashjs-player]';
scope = scope || document;
let videos = scope.querySelectorAll(selector);
for (let i = 0; i < videos.length; i++) {
let player = create(videos[i], null);
aPlayers.push(player);
}
let sources = scope.querySelectorAll('source[type="' + SUPPORTED_MIME_TYPE + '"]');
for (let i = 0; i < sources.length; i++) {
let video = findVideo(sources[i]);
let player = create(video, null);
aPlayers.push(player);
}
return aPlayers;
}
function findVideo(el) {
if ((/^VIDEO$/i).test(el.nodeName)) {
return el;
} else {
return findVideo(el.parentNode);
}
}
return {
create: create,
createAll: createAll
};
}
let instance = MediaPlayerFactory();
let loadInterval;
function loadHandler() {
window.removeEventListener('load', loadHandler);
instance.createAll();
}
function loadIntervalHandler() {
if (window.dashjs) {
window.clearInterval(loadInterval);
instance.createAll();
}
}
let avoidAutoCreate = typeof window !== 'undefined' && window && window.dashjs && window.dashjs.skipAutoCreate;
if (!avoidAutoCreate && typeof window !== 'undefined' && window && window.addEventListener) {
Iif (window.document.readyState === 'complete') {
if (window.dashjs) {
instance.createAll();
} else {
// If loaded asynchronously, window.readyState may be 'complete' even if dashjs hasn't loaded yet
loadInterval = window.setInterval(loadIntervalHandler, 500);
}
} else {
window.addEventListener('load', loadHandler);
}
}
export default instance;
|