Skip to content

Commit

Permalink
Added video quality feature (#43)
Browse files Browse the repository at this point in the history
* Fixed docker compose errors

* Added quality selector

* Remove log statement

Co-authored-by: Matthew Esposito <[email protected]>

* Show kbps in quality

Co-authored-by: Matthew Esposito <[email protected]>

* Make highest quality default

* Add styling, default option to highest

---------

Co-authored-by: Matthew Esposito <[email protected]>
  • Loading branch information
Carbrex and sigaloid authored Feb 6, 2024
1 parent fe6123e commit c603006
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
3 changes: 1 addition & 2 deletions docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ services:
read_only: true
security_opt:
- no-new-privileges:true
- seccomp="seccomp-redlib.json"
cap_drop:
- ALL
networks:
- redlib
security_opt:
- seccomp="seccomp-redlib.json"
healthcheck:
test: ["CMD", "wget", "--spider", "-q", "--tries=1", "http://localhost:8080/settings"]
interval: 5m
Expand Down
37 changes: 35 additions & 2 deletions static/playHLSVideo.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,21 @@

function initializeHls() {
newVideo.removeEventListener('play', initializeHls);

var hls = new Hls({ autoStartLoad: false });
hls.loadSource(playlist);
hls.attachMedia(newVideo);
hls.on(Hls.Events.MANIFEST_PARSED, function () {
hls.loadLevel = hls.levels.length - 1;
var availableLevels = hls.levels.map(function(level) {
return {
height: level.height,
width: level.width,
bitrate: level.bitrate,
};
});

addQualitySelector(newVideo, hls, availableLevels);

hls.startLoad();
newVideo.play();
});
Expand All @@ -61,6 +70,30 @@
});
}

function addQualitySelector(videoElement, hlsInstance, availableLevels) {
var qualitySelector = document.createElement('select');
qualitySelector.classList.add('quality-selector');
var last = availableLevels.length - 1;
availableLevels.forEach(function (level, index) {
var option = document.createElement('option');
option.value = index.toString();
var bitrate = (level.bitrate / 1_000).toFixed(0);
option.text = level.height + 'p (' + bitrate + ' kbps)';
if (index === last) {
option.selected = "selected";
}
qualitySelector.appendChild(option);
});
qualitySelector.selectedIndex = availableLevels.length - 1;
qualitySelector.addEventListener('change', function () {
var selectedIndex = qualitySelector.selectedIndex;
hlsInstance.nextLevel = selectedIndex;
hlsInstance.startLoad();
});

videoElement.parentNode.appendChild(qualitySelector);
}

newVideo.addEventListener('play', initializeHls);

if (autoplay) {
Expand All @@ -74,4 +107,4 @@
});
}
})();
// @license-end
// @license-end
16 changes: 16 additions & 0 deletions static/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -1714,3 +1714,19 @@ td, th {
justify-content: initial;
}
}

.quality-selector {
border: 2px var(--outside) solid;
margin-top: 8px;
float: right;
}

.quality-selector option {
background-color: var(--background);
color: var(--text);
}

.quality-selector option:hover {
background-color: var(--accent);
color: var(--text);
}

0 comments on commit c603006

Please sign in to comment.