modified: templates/quiz_multiplayer.html

This commit is contained in:
SimolZimol
2025-06-07 13:33:56 +02:00
parent 617eb12ddb
commit 6ca507933a

View File

@@ -177,8 +177,13 @@
function quizifyReady() {
// Musik abspielen, wenn Popup geschlossen
if (window.spotifyPlayer && window.spotifyPlayer._options && window.spotifyPlayer._options.getOAuthToken) {
function playTrackWhenReady() {
const device_id = document.getElementById('device_id').value;
if (!device_id) {
// Player ist noch nicht bereit, nochmal versuchen
setTimeout(playTrackWhenReady, 200);
return;
}
const playDuration = getPlayDuration();
const startPosition = getOption('startPosition', 'start');
let position_ms = 0;
@@ -190,10 +195,31 @@
if (playDuration > 0) {
window.quizifyTimeout = setTimeout(() => { window.spotifyPlayer.pause(); }, playDuration * 1000);
}
} else if (window.onSpotifyWebPlaybackSDKReady) {
window.onSpotifyWebPlaybackSDKReady();
setCorrectAnswer();
}
// Player initialisieren, falls nicht vorhanden
if (!window.spotifyPlayer) {
window.onSpotifyWebPlaybackSDKReady = () => {
const token = '{{ access_token }}';
const player = new Spotify.Player({
name: 'Musik Quiz Player',
getOAuthToken: cb => { cb(token); },
volume: 0.5
});
player.addListener('ready', ({ device_id }) => {
document.getElementById('device_id').value = device_id;
playTrackWhenReady();
});
player.connect();
window.spotifyPlayer = player;
};
if (window.onSpotifyWebPlaybackSDKReady) window.onSpotifyWebPlaybackSDKReady();
} else {
playTrackWhenReady();
}
setCorrectAnswer();
}
function setCorrectAnswer() {