* fixed autoplay

18l-fix
Dominika Liberda 2021-04-28 11:54:39 +00:00
parent 7ca97901ee
commit 1d4eb2f02a
3 changed files with 17 additions and 6 deletions

View File

@ -21,4 +21,3 @@
</div><h1>Comments</h1>
{{.comments_list}}
{{.playlist}}
<script type='text/javascript' src='js/player.js'></script>

View File

@ -20,7 +20,7 @@ window.addEventListener('DOMContentLoaded', (event) => {
});
console.log(formats);
if (localStorage.getItem("videoStream") == null) {
if (localStorage.getItem("videoStream") == null || localStorage.getItem("videoStream") == "") {
const videoFormat = formats.find((fmt) => fmt.vcodec !== 'none');
const audioFormat = videoFormat.acodec === 'none' ? formats.find((fmt) => fmt.acodec !== 'none') : null;
console.log('selected video format', videoFormat);
@ -30,7 +30,7 @@ window.addEventListener('DOMContentLoaded', (event) => {
} else {
let videoFormat = formats.find((fmt) => fmt.format_id == localStorage.getItem("videoStream"));
if (videoFormat == null) {
videoFormat = formats.find((fmt) => fmt.vcodec !== 'none');
videoFormat = formats.find((fmt) => fmt.vcodec !== 'none');
}
const audioFormat = videoFormat.acodec === 'none' ? formats.find((fmt) => fmt.format_id == localStorage.getItem("audioStream")) : null;
if (audioFormat == null) {
@ -162,10 +162,12 @@ window.addEventListener('DOMContentLoaded', (event) => {
}
function applyStreams() {
let autoplayInput = document.querySelector('#autoplayInput');
let videoStreamInput = document.querySelector('#videoStreamInput');
let audioStreamInput = document.querySelector('#audioStreamInput');
localStorage.setItem("videoStream", videoStreamInput.value);
localStorage.setItem("audioStream", audioStreamInput.value);
localStorage.setItem("autoplay", autoplayInput.checked);
const videoFormat = formats.find((fmt) => fmt.format_id == videoStreamInput.value);
const audioFormat = videoFormat.acodec === 'none' ? formats.find((fmt) => fmt.format_id == audioStreamInput.value) : null;
@ -247,6 +249,14 @@ window.addEventListener('DOMContentLoaded', (event) => {
document.querySelector('.ytp-volume-slider').addEventListener('click', (e) => volume(e));
document.querySelector('.ytp-button-fullscreen-enter').addEventListener('click', () => toggleFullscreen());
// autoplay
toggleVideo(true);
if(localStorage.getItem("autoplay") == "true") {
waiting = setInterval(()=> {
if(document.querySelector("video").readyState == 4) {
toggleVideo(true);
clearInterval(waiting)
} else {
console.log("waiting...")
}
},100);
}
});

File diff suppressed because one or more lines are too long