blob: 59a4b66eff8a3027ca1ef46b400271a6b6d49eed (
plain)
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
|
/**
* @file loader.js
*/
import Component from '../component.js';
import Tech from './tech.js';
import {toTitleCase} from '../utils/str.js';
import {merge} from '../utils/obj.js';
/** @import Player from '../player' */
/**
* The `MediaLoader` is the `Component` that decides which playback technology to load
* when a player is initialized.
*
* @extends Component
*/
class MediaLoader extends Component {
/**
* Create an instance of this class.
*
* @param {Player} player
* The `Player` that this class should attach to.
*
* @param {Object} [options]
* The key/value store of player options.
*
* @param {Function} [ready]
* The function that is run when this component is ready.
*/
constructor(player, options, ready) {
// MediaLoader has no element
const options_ = merge({createEl: false}, options);
super(player, options_, ready);
// If there are no sources when the player is initialized,
// load the first supported playback technology.
if (!options.playerOptions.sources || options.playerOptions.sources.length === 0) {
for (let i = 0, j = options.playerOptions.techOrder; i < j.length; i++) {
const techName = toTitleCase(j[i]);
let tech = Tech.getTech(techName);
// Support old behavior of techs being registered as components.
// Remove once that deprecated behavior is removed.
if (!techName) {
tech = Component.getComponent(techName);
}
// Check if the browser supports this technology
if (tech && tech.isSupported()) {
player.loadTech_(techName);
break;
}
}
} else {
// Loop through playback technologies (e.g. HTML5) and check for support.
// Then load the best source.
// A few assumptions here:
// All playback technologies respect preload false.
player.src(options.playerOptions.sources);
}
}
}
Component.registerComponent('MediaLoader', MediaLoader);
export default MediaLoader;
|