Merge branch '110-hintergrundmusik' into 'master'
Resolve "Hintergrundmusik?" Closes #110 See merge request enrichment-2024/qivip!76
This commit is contained in:
BIN
django/static/mp3/Hintergrundmusik.mp3
Normal file
BIN
django/static/mp3/Hintergrundmusik.mp3
Normal file
Binary file not shown.
@@ -73,6 +73,7 @@
|
|||||||
|
|
||||||
{% block extra_js %}
|
{% block extra_js %}
|
||||||
{% include 'play/game/common_scripts.html' %}
|
{% include 'play/game/common_scripts.html' %}
|
||||||
|
{% include 'play/game/sound.html' %}
|
||||||
<script>
|
<script>
|
||||||
const joinCode = '{{ quiz_game.join_code }}';
|
const joinCode = '{{ quiz_game.join_code }}';
|
||||||
const hostId = '{{ host_id }}';
|
const hostId = '{{ host_id }}';
|
||||||
|
|||||||
@@ -128,6 +128,9 @@
|
|||||||
</script>
|
</script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% include 'play/game/common_scripts.html' %}
|
{% include 'play/game/common_scripts.html' %}
|
||||||
|
{% if is_host %}
|
||||||
|
{% include 'play/game/sound.html' %}
|
||||||
|
{% endif %}
|
||||||
<script>
|
<script>
|
||||||
const joinCode = '{{ quiz_game.join_code }}';
|
const joinCode = '{{ quiz_game.join_code }}';
|
||||||
const hostId = '{{ host_id }}';
|
const hostId = '{{ host_id }}';
|
||||||
|
|||||||
29
django/templates/play/game/sound.html
Normal file
29
django/templates/play/game/sound.html
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
{% load static %}
|
||||||
|
|
||||||
|
|
||||||
|
<audio id="bg-music" src="{% static 'mp3/Hintergrundmusik.mp3' %}" autoplay loop ></audio>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
|
||||||
|
document.addEventListener("DOMContentLoaded", function () {
|
||||||
|
const audio = document.getElementById("bg-music");
|
||||||
|
const savedTime = localStorage.getItem("bg-music-time");
|
||||||
|
|
||||||
|
if (savedTime) {
|
||||||
|
audio.addEventListener("loadedmetadata", () => {
|
||||||
|
audio.currentTime = parseFloat(savedTime);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener("click", () => {
|
||||||
|
audio.play().catch(e => console.warn("Autoplay blockiert:", e));
|
||||||
|
}, { once: true });
|
||||||
|
|
||||||
|
setInterval(() => {
|
||||||
|
if (!audio.paused) {
|
||||||
|
localStorage.setItem("bg-music-time", audio.currentTime);
|
||||||
|
}
|
||||||
|
}, 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
</script>
|
||||||
Reference in New Issue
Block a user