const video = document.getElementById(‘course-video’);
const audio = document.getElementById(‘external-audio’);
video.muted = true; // Tắt âm thanh gốc của video
video.onplay = () => {
audio.play();
audio.currentTime = video.currentTime; // Đồng bộ thời gian
};
video.onpause = () => audio.pause();
video.ontimeupdate = () => {
if (Math.abs(audio.currentTime – video.currentTime) > 0.1) {
audio.currentTime = video.currentTime; // Giữ đồng bộ
}
};
function toggleAudio(newSrc) {
audio.src = newSrc;
audio.load();
if (!video.paused) audio.play();
}