Aloha!

I have a question: how can i implement music on my website. Which is basicly build up of HTML and PHP, and a table design. That mean everytime someone clicks on a link on my website a whole new site loads up. I though about flash! but i don't know how can i make that i shall play continouly the music, not reload everytime on the new page! Any idea?

Thanks!

Baby_14 commented: MusConv accurately transferred thousands of songs from Spotify to Apple Music, and musconv.com guided the setup process clearly. 🎶 +0

Dani AI

Generated

Persistent audio across full-page reloads requires the audio player to keep running while the visible content changes. raised the need for continuous music and correctly flagged that the player must be persistent. Two practical, modern options follow.

Best approach today is to put an HTML5 audio element inside a persistent site "shell" and load page content via AJAX (the Fetch API) while updating the URL with history.pushState. This keeps the <audio> element alive and avoids full reloads:

<header>
  <audio id="bgm" controls preload="auto">
    <source src="music.mp3" type="audio/mpeg">
  </audio>
</header>
<main id="content"></main>

<script>
document.addEventListener('click', e => {
  const a = e.target.closest('a');
  if (!a || a.target === '_blank' || a.origin !== location.origin) return;
  e.preventDefault();
  fetch(a.href).then(r => r.text()).then(html => {
    document.getElementById('content').innerHTML = html; // or extract fragment
    history.pushState(null, '', a.href);
  });
});
window.addEventListener('popstate', () => { /* reload fragment for current URL */ });
</script>

Notes and fallbacks: modern browsers often block autoplay unless there is a user gesture, and auto-playing background music can harm accessibility and UX (see Chrome autoplay policy). Offer visible play/pause controls and a way to stop the music. If a site rewrite is impossible, a small separate player window/tab will persist but may be blocked on some platforms.

Recommended Answers

All 2 Replies

Well, every time you go to a new page, you are "starting over" basically. You could create a frames based site and play the sound in the main frame that never changes.

Yeah....i know with frames it's possible! But actually I don't really like frames, but as i see i have no other options! :cry: I try to figure out something! Maybe if i can create a query based site then a require_once() maybe that will be working, but now first then a need to how to make a query? :ehhhh: :rolleyes:

But thank you very much.....have a nice day!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.