Browse Source

improve selectrandomvideo

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

29
script.js

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

Loading…
Cancel
Save