Hi everyone,

Does anyone have any ideas on how to intall a music player in a php page where the file name is called from a mysql database. I have done this within html 5 with audio tag but however I need to stop the preload of the music and I am having difficulty finding a solution. But I am open to any ideas thrown at me to be honest.

Regards.

Gav.

Dani AI

Generated

Short answer: for self‑hosted files the most reliable way to prevent any preloading is to avoid putting the file URL into the audio element until the user explicitly requests playback. That handles the issue better than relying on the preload hint (browsers treat preload as advisory and some still fetch small files).

A simple pattern you can generate from PHP/MySQL is: output a play control with a safe data attribute (the filename or an ID), keep a single <audio> with preload="none", and set audio.src only when the user clicks. Example markup and javascript:

<!-- PHP: echo a button per DB row -->
<button class="play" data-src="uploads/song.mp3">Play</button>

<audio id="player" controls preload="none"></audio>

<script>
document.addEventListener('click', function(e){
  if (e.target.matches('.play')) {
    var src = e.target.getAttribute('data-src');
    var player = document.getElementById('player');
    if (player.getAttribute('data-current') !== src) {
      player.src = src;
      player.setAttribute('data-current', src);
      player.load();
    }
    player.play();
  }
});
</script>

Troubleshooting notes: make sure the server sends the correct MIME type (audio/mpeg) and supports HTTP Range requests (seeking needs this). If you serve files through a PHP proxy, send proper headers (Content-Type, Accept-Ranges, Content-Length) and avoid extra output buffering/whitespace. Watch for cross‑domain/CORS issues if audio lives on another host. Mobile browsers commonly block autoplay, so the user‑click approach also improves mobile reliability.

Security & UX: never echo unsanitized paths from the DB — map an ID to a server path or use rawurlencode()/htmlspecialchars() when outputting. For richer hosting features you can consider third‑party services (as mentioned), but avoid Flash (as suggested) since it is deprecated and lacks mobile support. This approach keeps the UI simple, prevents unwanted downloads, and ties cleanly into a PHP+MySQL workflow (as hinted) while giving you direct control over when audio is fetched.

Recommended Answers

All 3 Replies

hi there are lots of PHP scripets are avaliable in market you just google it and find the correct scripets for this issue ...

yes creat a small flash mp3 plyer & use it w/ it set w/ autoplay:off;

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.