Browse Source

improve selectrandomvideo

master
HxxxxxS 2 years ago
parent
commit
b6c8bb1a35
  1. 33
      script.js

33
script.js

@ -129,8 +129,6 @@ function drawDebugText() {
});
}
// Function to extract filename from full path
function getFilename(src) {
const parts = src.split('/');
@ -160,25 +158,22 @@ window.addEventListener("resize", updateCanvasSize);
updateCanvasSize()
function selectRandomVideo(videoElement) {
console.log("selectRandomVideo",videoElement)
fetch("/api/videos")
.then((response) => response.json())
.then((videoFiles) => {
const otherVideo = videos.find((video) => video !== videoElement);
let randomVideo;
do {
const randomIndex = Math.floor(Math.random() * videoFiles.length);
randomVideo = videoFiles[randomIndex];
} while (randomVideo === otherVideo);
videoElement.src = randomVideo.src;
videoElement.play();
return videoElement
});
fetch("/api/videos")
.then(response => response.json())
.then(videoFiles => {
const currentSrc = videoElement.src;
const filteredVideos = videoFiles.filter(video => video.src !== currentSrc);
if (filteredVideos.length > 0) {
const randomIndex = Math.floor(Math.random() * filteredVideos.length);
const randomVideo = filteredVideos[randomIndex];
videoElement.src = randomVideo.src;
} else {
console.log("No other videos available.");
}
})
.catch(error => console.error("Error fetching videos:", error));
}
document.addEventListener('keydown', function(event) {
console.log('keyDown',event)
// Check if the pressed key is the one you want to bind

Loading…
Cancel
Save