No ; in sight

This commit is contained in:
Korbs 2024-11-04 13:38:00 -05:00
parent 16be696f91
commit af9028db95

View file

@ -27,16 +27,16 @@
*/ */
// https://gist.github.com/michancio/59b9f3dc54b3ff4f6a84 // https://gist.github.com/michancio/59b9f3dc54b3ff4f6a84
// Find elements // Find elements
var SyncVideo = document.querySelector(".main-video"); var SyncVideo = document.querySelector(".main-video")
var SyncAudio = document.querySelector(".main-audio"); var SyncAudio = document.querySelector(".main-audio")
// Object for synchronization of multiple media/sources // Object for synchronization of multiple media/sources
if (typeof window.MediaController === "function") { if (typeof window.MediaController === "function") {
var controller = new MediaController(); var controller = new MediaController()
SyncVideo.controller = controller; SyncVideo.controller = controller
SyncAudio.controller = controller; SyncAudio.controller = controller
} else { } else {
controller = null; controller = null
} }
// Run SyncAudio and SyncVideo simultaneously // Run SyncAudio and SyncVideo simultaneously
@ -44,49 +44,49 @@ SyncVideo.addEventListener(
"play", "play",
function () { function () {
if (!controller && SyncAudio.paused) { if (!controller && SyncAudio.paused) {
SyncAudio.play(); SyncAudio.play()
} }
}, },
false, false,
); )
// Pause/Play and Buffering // Pause/Play and Buffering
SyncVideo.addEventListener("waiting", () => { SyncVideo.addEventListener("waiting", () => {
// If SyncVideo is buffering // If SyncVideo is buffering
SyncAudio.pause(); SyncAudio.pause()
}); })
SyncVideo.addEventListener("playing", () => { SyncVideo.addEventListener("playing", () => {
// If SyncVideo is done buffering // If SyncVideo is done buffering
SyncAudio.play(); SyncAudio.play()
SyncTimestamp(); SyncTimestamp()
}); })
SyncVideo.addEventListener( SyncVideo.addEventListener(
"pause", "pause",
function () { function () {
if (!controller && !SyncAudio.paused) { if (!controller && !SyncAudio.paused) {
SyncAudio.pause(); SyncAudio.pause()
} }
}, },
false, false,
); )
// When Media Ends // When Media Ends
SyncVideo.addEventListener( SyncVideo.addEventListener(
"ended", "ended",
function () { function () {
if (controller) { if (controller) {
controller.pause(); controller.pause()
} else { } else {
SyncVideo.pause(); SyncVideo.pause()
SyncAudio.pause(); SyncAudio.pause()
} }
}, },
false, false,
); )
// Seekbar // Seekbar
function SyncTimestamp() { function SyncTimestamp() {
SyncAudio.currentTime = SyncVideo.currentTime; SyncAudio.currentTime = SyncVideo.currentTime
} }
</script> </script>