modified: templates/quiz_multiplayer.html
This commit is contained in:
@@ -177,8 +177,13 @@
|
|||||||
|
|
||||||
function quizifyReady() {
|
function quizifyReady() {
|
||||||
// Musik abspielen, wenn Popup geschlossen
|
// 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;
|
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 playDuration = getPlayDuration();
|
||||||
const startPosition = getOption('startPosition', 'start');
|
const startPosition = getOption('startPosition', 'start');
|
||||||
let position_ms = 0;
|
let position_ms = 0;
|
||||||
@@ -190,10 +195,31 @@
|
|||||||
if (playDuration > 0) {
|
if (playDuration > 0) {
|
||||||
window.quizifyTimeout = setTimeout(() => { window.spotifyPlayer.pause(); }, playDuration * 1000);
|
window.quizifyTimeout = setTimeout(() => { window.spotifyPlayer.pause(); }, playDuration * 1000);
|
||||||
}
|
}
|
||||||
} else if (window.onSpotifyWebPlaybackSDKReady) {
|
setCorrectAnswer();
|
||||||
window.onSpotifyWebPlaybackSDKReady();
|
}
|
||||||
|
|
||||||
|
// 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() {
|
function setCorrectAnswer() {
|
||||||
|
|||||||
Reference in New Issue
Block a user