Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: mirror player.src on the demo page demo page #1071

Merged
merged 2 commits into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ <h3>Options</h3>
<input id=override-native type="checkbox" checked>
Override Native (reloads player)
</label>
<label>
<input id=mirror-source type="checkbox" checked>
Mirror sources from player.src (reloads player, uses EXPERIMENTAL sourceset option)
</label>
<label>
Preload (reloads player)
<select id=preload>
Expand Down
54 changes: 53 additions & 1 deletion scripts/index-demo-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,22 @@
representationsEl.selectedIndex = selectedIndex;
};

['debug', 'autoplay', 'muted', 'minified', 'sync-workers', 'liveui', 'partial', 'url', 'type', 'keysystems', 'buffer-water', 'override-native', 'preload'].forEach(function(name) {
[
'debug',
'autoplay',
'muted',
'minified',
'sync-workers',
'liveui',
'partial',
'url',
'type',
'keysystems',
'buffer-water',
'override-native',
'preload',
'mirror-source'
].forEach(function(name) {
stateEls[name] = document.getElementById(name);
});

Expand All @@ -252,6 +267,13 @@
window.player.autoplay(event.target.checked);
});

stateEls['mirror-source'].addEventListener('change', function(event) {
saveState();

// reload the player and scripts
stateEls.minified.dispatchEvent(newEvent('change'));
});

stateEls['sync-workers'].addEventListener('change', function(event) {
saveState();

Expand Down Expand Up @@ -333,13 +355,16 @@
videoEl.className = 'vjs-default-skin';
fixture.appendChild(videoEl);

const mirrorSource = getInputValue(stateEls['mirror-source']);

player = window.player = window.videojs(videoEl, {
plugins: {
httpSourceSelector: {
default: 'auto'
}
},
liveui: stateEls.liveui.checked,
enableSourceset: mirrorSource,
html5: {
vhs: {
overrideNative: getInputValue(stateEls['override-native']),
Expand All @@ -349,6 +374,33 @@
}
});

player.on('sourceset', function() {
const source = player.currentSource();

if (source.keySystems) {
const copy = JSON.parse(JSON.stringify(source.keySystems));

// have to delete pssh as it will often make keySystems too big
// for a uri
Object.keys(copy).forEach(function(key) {
if (copy[key].hasOwnProperty('pssh')) {
delete copy[key].pssh;
}
});

stateEls.keysystems.value = JSON.stringify(copy, null, 2);
}

if (source.src) {
stateEls.url.value = source.src;
}

if (source.type) {
stateEls.type.value = source.type;
}

});

player.width(640);
player.height(264);

Expand Down