-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
96 lines (80 loc) · 2.67 KB
/
index.html
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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>videojs-per-source-behaviors Demo</title>
<link href="/node_modules/video.js/dist/video-js.css" rel="stylesheet">
</head>
<body>
<video id="videojs-per-source-behaviors-player" class="video-js" controls></video>
<p>
<button id="change-source">Change the Source</button>
</p>
<ul>
<li><a href="/test/debug.html">Run unit tests in browser.</a></li>
</ul>
<script src="/node_modules/video.js/dist/video.js"></script>
<script src="/dist/videojs-per-source-behaviors.js"></script>
<script>
(function(window, videojs) {
console.log('to view the current state, call `console.table(playerEvents);`');
var player = window.player = videojs('videojs-per-source-behaviors-player');
var sources = [
'https://vjs.zencdn.net/v/oceans.mp4',
'https://archive.org/download/ElephantsDream/ed_hd.mp4',
'https://archive.org/download/Sintel/sintel-2048-stereo_512kb.mp4'
];
var currentSource = 0;
var networkStates = [
'NETWORK_EMPTY',
'NETWORK_IDLE',
'NETWORK_LOADING',
'NETWORK_NO_SOURCE'
];
var readyStates = [
'HAVE_NOTHING',
'HAVE_METADATA',
'HAVE_CURRENT_DATA',
'HAVE_FUTURE_DATA',
'HAVE_ENOUGH_DATA'
];
var playerEvents = window.playerEvents = [];
player.on(videojs.getTech('Html5').Events, function(e) {
videojs.log(e.type + ' at ' + Date.now());
playerEvents.push({
networkState: networkStates[player.networkState()],
readyState: readyStates[player.readyState()],
time: Date.now(),
type: e.type
});
});
player.on(['sourceunstable', 'sourcechanged'], function(e, data) {
videojs.log(e.type.toUpperCase() + ' at ' + Date.now());
playerEvents.push({
data: data,
networkState: networkStates[player.networkState()],
readyState: readyStates[player.readyState()],
time: Date.now(),
type: e.type
});
});
player.perSourceBehaviors();
player.src(sources[currentSource]);
var changeSourceBtn = document.getElementById('change-source');
changeSourceBtn.addEventListener('click', function(e) {
var wasPlaying = !player.paused();
e.preventDefault();
currentSource++;
if (currentSource === sources.length) {
currentSource = 0;
}
videojs.log('about to change the source');
player.src(sources[currentSource]);
if (wasPlaying) {
player.play();
}
});
}(window, window.videojs));
</script>
</body>
</html>