Merge pull request 'Add countdown audio per presentation' (#117) from feature/quiz-audio into main
CI / Deploy / PHP 8.4 (push) Successful in 1m16s
CI / Deploy / PHP 8.5 (push) Successful in 1m34s
CI / Deploy / test (push) Successful in 2s
CI / Deploy / deploy (push) Successful in 7s

Reviewed-on: #117
This commit was merged in pull request #117.
This commit is contained in:
gnilebein committed 2026-11-21 11:46:28 +01:00
commit 918270540f
16 files changed
+648 -11

No files matched your search

+66
View File
@@ -204,6 +204,70 @@
}
};
// ------------------------------------------------------------------ stage audio
/**
* Music of the presentation (presenter view only): plays in a loop while a quiz runs, so it also covers a
* countdown that is longer than the file, and stops when the quiz ends or the slide changes.
* Browsers may refuse to start audio without a previous click or key press; the presenter has
* always pressed something to start the quiz, and a refused start is retried on the next one.
*/
var StageAudio = {
element: null,
url: null,
wanted: false,
/** @param {string|null} url audio URL of the poll, only passed while a quiz is running */
sync: function (url) {
StageAudio.wanted = !!url;
if (!url) {
StageAudio.stop();
return;
}
if (!StageAudio.element) {
StageAudio.element = new Audio();
StageAudio.element.loop = true;
StageAudio.element.preload = 'auto';
}
var audio = StageAudio.element;
if (StageAudio.url !== url) {
StageAudio.url = url;
audio.src = url;
}
if (audio.paused) {
StageAudio.play();
}
},
play: function () {
var attempt = StageAudio.element && StageAudio.element.play();
if (attempt && attempt.catch) {
attempt.catch(function () {
// Blocked (no user activation yet): try again on the next click or key press.
var retry = function () {
document.removeEventListener('click', retry, true);
document.removeEventListener('keydown', retry, true);
if (StageAudio.wanted && StageAudio.element && StageAudio.element.paused) {
StageAudio.play();
}
};
document.addEventListener('click', retry, true);
document.addEventListener('keydown', retry, true);
});
}
},
stop: function () {
StageAudio.wanted = false;
if (StageAudio.element && !StageAudio.element.paused) {
StageAudio.element.pause();
}
if (StageAudio.element && StageAudio.element.currentTime) {
StageAudio.element.currentTime = 0;
}
}
};
// ------------------------------------------------------------------ word matching
/**
@@ -1454,6 +1518,7 @@
root.classList.remove('stage--video');
q('[data-voting]').hidden = true;
setText('[data-participants]', '');
StageAudio.stop();
return;
}
@@ -1498,6 +1563,7 @@
}
renderResults();
Countdown.start();
StageAudio.sync(quizPhase === 'running' ? state.poll.audioUrl : null);
}
function isPrivate() {