Skip to content

Commit fee7309

Browse files
committed
chore: mirror player.src on the demo page using sourceset (#1071)
1 parent e583b26 commit fee7309

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

index.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ <h3>Options</h3>
8888
<input id=override-native type="checkbox" checked>
8989
Override Native (reloads player)
9090
</label>
91+
<label>
92+
<input id=mirror-source type="checkbox" checked>
93+
Mirror sources from player.src (reloads player, uses EXPERIMENTAL sourceset option)
94+
</label>
9195
<label>
9296
Preload (reloads player)
9397
<select id=preload>

scripts/index-demo-page.js

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,22 @@
225225
representationsEl.selectedIndex = selectedIndex;
226226
};
227227

228-
['debug', 'autoplay', 'muted', 'minified', 'sync-workers', 'liveui', 'partial', 'url', 'type', 'keysystems', 'buffer-water', 'override-native', 'preload'].forEach(function(name) {
228+
[
229+
'debug',
230+
'autoplay',
231+
'muted',
232+
'minified',
233+
'sync-workers',
234+
'liveui',
235+
'partial',
236+
'url',
237+
'type',
238+
'keysystems',
239+
'buffer-water',
240+
'override-native',
241+
'preload',
242+
'mirror-source'
243+
].forEach(function(name) {
229244
stateEls[name] = document.getElementById(name);
230245
});
231246

@@ -252,6 +267,13 @@
252267
window.player.autoplay(event.target.checked);
253268
});
254269

270+
stateEls['mirror-source'].addEventListener('change', function(event) {
271+
saveState();
272+
273+
// reload the player and scripts
274+
stateEls.minified.dispatchEvent(newEvent('change'));
275+
});
276+
255277
stateEls['sync-workers'].addEventListener('change', function(event) {
256278
saveState();
257279

@@ -333,13 +355,16 @@
333355
videoEl.className = 'vjs-default-skin';
334356
fixture.appendChild(videoEl);
335357

358+
const mirrorSource = getInputValue(stateEls['mirror-source']);
359+
336360
player = window.player = window.videojs(videoEl, {
337361
plugins: {
338362
httpSourceSelector: {
339363
default: 'auto'
340364
}
341365
},
342366
liveui: stateEls.liveui.checked,
367+
enableSourceset: mirrorSource,
343368
html5: {
344369
vhs: {
345370
overrideNative: getInputValue(stateEls['override-native']),
@@ -349,6 +374,34 @@
349374
}
350375
});
351376

377+
player.on('sourceset', function() {
378+
const source = player.currentSource();
379+
380+
if (source.keySystems) {
381+
const copy = JSON.parse(JSON.stringify(source.keySystems));
382+
383+
// have to delete pssh as it will often make keySystems too big
384+
// for a uri
385+
Object.keys(copy).forEach(function(key) {
386+
if (copy[key].hasOwnProperty('pssh')) {
387+
delete copy[key].pssh;
388+
}
389+
});
390+
391+
stateEls.keysystems.value = JSON.stringify(copy, null, 2);
392+
}
393+
394+
if (source.src) {
395+
stateEls.url.value = source.src;
396+
}
397+
398+
if (source.type) {
399+
stateEls.type.value = source.type;
400+
}
401+
402+
saveState();
403+
});
404+
352405
player.width(640);
353406
player.height(264);
354407

0 commit comments

Comments
 (0)