mirror of
https://github.com/videojs/video.js.git
synced 2024-11-24 08:42:25 +02:00
feat: add support for a list of quality levels (#7897)
This brings the videojs-contrib-quality-levels plugin into Video.js as a feature.
This commit is contained in:
parent
91f4663ea5
commit
54195f0b28
@ -24,6 +24,7 @@
|
||||
<li><a href="sandbox/language.html">Language Demo</a></li>
|
||||
<li><a href="sandbox/load-media.html"><code>loadMedia</code> Demo</a></li>
|
||||
<li><a href="sandbox/hls.html">Hls Demo</a></li>
|
||||
<li><a href="sandbox/quality-levels.html">QualityLevels Demo</a></li>
|
||||
<li><a href="sandbox/autoplay-tests.html">Autoplay Tests</a></li>
|
||||
<li><a href="sandbox/noUITitleAttributes.html">noUITitleAttributes Demo</a></li>
|
||||
<li><a href="sandbox/debug.html">Videojs debug build test page</a></li>
|
||||
|
4527
package-lock.json
generated
4527
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -94,6 +94,7 @@
|
||||
"mpd-parser": "1.0.0",
|
||||
"mux.js": "6.2.0",
|
||||
"safe-json-parse": "4.0.0",
|
||||
"videojs-contrib-quality-levels": "^2.2.0",
|
||||
"videojs-font": "3.2.0",
|
||||
"videojs-vtt.js": "^0.15.4"
|
||||
},
|
||||
|
@ -227,6 +227,7 @@ export default cliargs => [
|
||||
plugins: [
|
||||
alias({
|
||||
'video.js': path.resolve(__dirname, './src/js/video.js'),
|
||||
'videojs-contrib-quality-levels': path.resolve(__dirname, './node_modules/videojs-contrib-quality-levels/dist/videojs-contrib-quality-levels.es.js'),
|
||||
'@videojs/http-streaming': path.resolve(__dirname, './node_modules/@videojs/http-streaming/dist/videojs-http-streaming.es.js')
|
||||
}),
|
||||
replace({
|
||||
|
109
sandbox/quality-levels.html.example
Normal file
109
sandbox/quality-levels.html.example
Normal file
@ -0,0 +1,109 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8" />
|
||||
<title>Video.js Sandbox</title>
|
||||
<link href="../dist/video-js.css" rel="stylesheet" type="text/css">
|
||||
<style>
|
||||
.btn {
|
||||
background-color: #5cb85c;
|
||||
border-radius: 0.5em;
|
||||
border: 1px solid #18ab29;
|
||||
display: inline-block;
|
||||
cursor: pointer;
|
||||
color: #ffffff;
|
||||
font-size: 1em;
|
||||
padding: 0.5em;
|
||||
margin: 0.25em 0.25em 0.25em 0;
|
||||
}
|
||||
|
||||
.btn-success {
|
||||
font-weight: bold;
|
||||
background-color: #337ab7;
|
||||
}
|
||||
</style>
|
||||
<script src="../dist/video.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div
|
||||
style="background-color:#eee; border: 1px solid #777; padding: 10px; margin-bottom: 20px; font-size: .8em; line-height: 1.5em; font-family: Verdana, sans-serif;">
|
||||
<p>You can use /sandbox/ for writing and testing your own code. Nothing in /sandbox/ will get checked into the repo,
|
||||
except files that end in .example (so don't edit or add those files). To get started make a copy of
|
||||
index.html.example and rename it to index.html.</p>
|
||||
<pre>cp sandbox/index.html.example sandbox/index.html</pre>
|
||||
<pre>npm run start</pre>
|
||||
<pre>open http://localhost:9999/sandbox/index.html</pre>
|
||||
</div>
|
||||
<div style="width: 65%;">
|
||||
<video-js id="vid1" controls preload="auto" class="vjs-fluid">
|
||||
<source src="https://d2zihajmogu5jn.cloudfront.net/bipbop-advanced/bipbop_16x9_variant.m3u8"
|
||||
type="application/x-mpegURL">
|
||||
<p class="vjs-no-js">To view this video please enable JavaScript, and consider upgrading to a web browser that <a
|
||||
href="https://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a></p>
|
||||
</video-js>
|
||||
</div>
|
||||
<div id="currentLevelControl" style="width: 100%;">
|
||||
<button id="autoBtn" type="button" class="btn btn-success">Auto</button>
|
||||
</div>
|
||||
<script>
|
||||
const vid = document.getElementById('vid1');
|
||||
const player = videojs(vid, {
|
||||
qualityLevels: true
|
||||
});
|
||||
player.one('loadedmetadata', () => {
|
||||
const container = document.getElementById('currentLevelControl');
|
||||
const autoBtn = document.getElementById('autoBtn');
|
||||
const btnList = [];
|
||||
// create a button for every video quality level
|
||||
for (let i = 0; i < player.qualityLevels().length; i++) {
|
||||
let level = player.qualityLevels()[i];
|
||||
if (level.width === undefined) {
|
||||
continue;
|
||||
}
|
||||
let levelElm = document.createElement('button');
|
||||
levelElm.classList.add('btn');
|
||||
if (player.qualityLevels().selectedIndex === i) {
|
||||
levelElm.classList.add('btn-success');
|
||||
}
|
||||
levelElm.setAttribute('title', level.label);
|
||||
levelElm.setAttribute('type', 'button');
|
||||
levelElm.setAttribute('data-level', i);
|
||||
levelElm.innerText = `${i} ('${level.width}': ${level.height}p, ${(level.bitrate / 1024).toFixed(0)}kb)`;
|
||||
btnList.push(levelElm);
|
||||
container.append(levelElm);
|
||||
}
|
||||
// attach a click handler to buttons
|
||||
for (const btn of btnList) {
|
||||
btn.addEventListener('click', (event) => {
|
||||
const selectedIndex = player.qualityLevels().selectedIndex;
|
||||
const btnIndex = event.target.dataset.level;
|
||||
autoBtn.classList.remove('btn-success');
|
||||
if (selectedIndex == btnIndex) {
|
||||
return;
|
||||
}
|
||||
btnList.forEach((elm) => {
|
||||
player.qualityLevels()[elm.dataset.level].enabled = elm.dataset.level === btnIndex;
|
||||
});
|
||||
});
|
||||
}
|
||||
// update buttons on video quality changes
|
||||
player.qualityLevels().on('change', (event) => {
|
||||
for (let btn of btnList) {
|
||||
if (btn.dataset.level == event.selectedIndex) {
|
||||
btn.classList.add('btn-success');
|
||||
} else {
|
||||
btn.classList.remove('btn-success');
|
||||
}
|
||||
}
|
||||
});
|
||||
// add a click handler to reset previously selected video quality by the user
|
||||
autoBtn.addEventListener('click', (event) => {
|
||||
btnList.forEach((elm) => {
|
||||
player.qualityLevels()[elm.dataset.level].enabled = true;
|
||||
});
|
||||
autoBtn.classList.toggle('btn-success', true);
|
||||
});
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
@ -1,4 +1,5 @@
|
||||
import videojs from './video';
|
||||
import 'videojs-contrib-quality-levels';
|
||||
import '@videojs/http-streaming';
|
||||
import DomData from './utils/dom-data.js';
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
import videojs from './video';
|
||||
import 'videojs-contrib-quality-levels';
|
||||
import '@videojs/http-streaming';
|
||||
export default videojs;
|
||||
|
Loading…
Reference in New Issue
Block a user