Spaces:
Running
Running
Update script.js
Browse files
script.js
CHANGED
|
@@ -212,4 +212,58 @@ function initVideoLibrary() {
|
|
| 212 |
});
|
| 213 |
|
| 214 |
renderVideos(ALL_VIDEOS);
|
| 215 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
});
|
| 213 |
|
| 214 |
renderVideos(ALL_VIDEOS);
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
// --- BACKGROUND MUSIC PLAYER ---
|
| 218 |
+
|
| 219 |
+
let player;
|
| 220 |
+
let musicPlaying = false;
|
| 221 |
+
|
| 222 |
+
// This function creates an <iframe> (YouTube player) after the API code downloads.
|
| 223 |
+
function onYouTubeIframeAPIReady() {
|
| 224 |
+
player = new YT.Player('youtube-player', {
|
| 225 |
+
height: '0',
|
| 226 |
+
width: '0',
|
| 227 |
+
videoId: 'IzogBJpcEWg', // Saudi National Anthem Video ID
|
| 228 |
+
playerVars: {
|
| 229 |
+
'autoplay': 0,
|
| 230 |
+
'controls': 0,
|
| 231 |
+
'loop': 1,
|
| 232 |
+
'playlist': 'IzogBJpcEWg', // Required for loop to work
|
| 233 |
+
'volume': 30 // Set volume to 30%
|
| 234 |
+
},
|
| 235 |
+
events: {
|
| 236 |
+
'onReady': onPlayerReady
|
| 237 |
+
}
|
| 238 |
+
});
|
| 239 |
+
}
|
| 240 |
+
|
| 241 |
+
// The API will call this function when the video player is ready.
|
| 242 |
+
function onPlayerReady(event) {
|
| 243 |
+
// Player is ready, you could optionally play on load here, but we'll use a button
|
| 244 |
+
// event.target.playVideo();
|
| 245 |
+
}
|
| 246 |
+
|
| 247 |
+
// Function to toggle music play/pause
|
| 248 |
+
function toggleBackgroundMusic() {
|
| 249 |
+
const toggleButton = document.getElementById('music-toggle');
|
| 250 |
+
if (musicPlaying) {
|
| 251 |
+
player.pauseVideo();
|
| 252 |
+
toggleButton.innerHTML = '<i class="fas fa-music text-xl"></i>';
|
| 253 |
+
toggleButton.classList.remove('bg-brand-gold'); // Remove active state color
|
| 254 |
+
musicPlaying = false;
|
| 255 |
+
} else {
|
| 256 |
+
player.playVideo();
|
| 257 |
+
toggleButton.innerHTML = '<i class="fas fa-pause text-xl"></i>';
|
| 258 |
+
toggleButton.classList.add('bg-brand-gold'); // Add active state color
|
| 259 |
+
musicPlaying = true;
|
| 260 |
+
}
|
| 261 |
+
}
|
| 262 |
+
|
| 263 |
+
// Add event listener to the button
|
| 264 |
+
document.addEventListener('DOMContentLoaded', () => {
|
| 265 |
+
const musicButton = document.getElementById('music-toggle');
|
| 266 |
+
if (musicButton) {
|
| 267 |
+
musicButton.addEventListener('click', toggleBackgroundMusic);
|
| 268 |
+
}
|
| 269 |
+
});
|