modified: templates/quiz_multiplayer.html
This commit is contained in:
@@ -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,12 +195,33 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
function setCorrectAnswer() {
|
||||
if (currentGameMode === 'artist') {
|
||||
correctAnswer = "{{ track.artists[0].name }}";
|
||||
|
||||
Reference in New Issue
Block a user