{% 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>