Hi,

now i m working for musical website...

here my problem is how can i create a playlist and how to pass the selected songs to my player....


i dont have any idea regarding this.. plz give me JAVASCRIPT, php code ...

plz give me some suggestions...sorry for asking code..but i m new to this type of project....

Thanks..

Dani AI

Generated

Short summary and recommended approach. The Flash-based route mentioned by works, but a simpler, more future‑proof solution is an HTML5 <audio> + JavaScript front end with a tiny PHP endpoint that emits a playlist (JSON or XML). That directly solves the two problems reported by : (1) filenames with spaces/hyphens breaking the player, and (2) the playlist showing full file paths instead of friendly song titles.

Server workflow (PHP): scan the music folder, optionally extract ID3 metadata (getID3 library), and emit a JSON array where each item contains an encoded file URL and a display title. Encoding the filename prevents “spaces break links” issues.

<?php
$dir = 'music';
$files = glob("$dir/*.mp3");
$plist = [];
foreach ($files as $f) {
  $b = basename($f);
  $plist[] = [
    'file'  => $dir . '/' . rawurlencode($b),
    'title' => pathinfo($b, PATHINFO_FILENAME)
  ];
}
header('Content-Type: application/json');
echo json_encode($plist);

Client-side (JavaScript): fetch the JSON, create list items showing cleaned titles (replace underscores/hyphens), and set the audio element's src to the encoded URL when a track is chosen.

fetch('/playlist.php')
  .then(r => r.json())
  .then(list => {
    const audio = document.querySelector('audio');
    const ul = document.getElementById('playlist');
    list.forEach(t => {
      const li = document.createElement('li');
      li.textContent = t.title.replace(/[-_]/g,' ');
      li.onclick = () => { audio.src = t.file; audio.play(); };
      ul.appendChild(li);
    });
  });

Troubleshooting and tips: use rawurlencode (PHP) or encodeURIComponent (JS) so spaces become %20; do not rely on client-side string replacement as a substitute for proper URL encoding. To show artist/title/duration, extract ID3 tags server-side (getID3) or read audio.duration and audio.buffered client-side for buffering info. Ensure the server sends correct MIME (audio/mpeg) and supports byte‑range requests (needed for seeking and smooth buffering). If continuing with a Flash player, the same URL‑encoding principle applies.

Recommended Answers

All 5 Replies

It would need to be done in Flash, not Javascript. I am working on a similar project and my player is roughly based on the source of this

It would need to be done in Flash, not Javascript. I am working on a similar project and my player is roughly based on the source of this

hi Samarudge,

Thanks a lot...Its working fine...

But here i m facing some problems...


1) here the file name doesn't take SPACES , -...
2)in playlist it displays full path of the song...is there any option to remove this..i want to display file name only...

once again thanks a lot..

Give me some suggestions to solve this problem.

All those players are open-source so you can download the source ActionScript 3 files and edit them to your liking, i managed to edit that to get its souce files from an XML source (Dynamicaly)
If you want help with the ActionScript, start a new thread in this forum
http://www.daniweb.com/forums/forum28.html

All those players are open-source so you can download the source ActionScript 3 files and edit them to your liking, i managed to edit that to get its souce files from an XML source (Dynamicaly)
If you want help with the ActionScript, start a new thread in this forum
http://www.daniweb.com/forums/forum28.html

Hi ...i m sorry to ask..can u send me the code..if there is no prob to u....

Hi ...i m sorry to ask..can u send me the code..if there is no prob to u....

Hi ...

I got every thing wat i want by following ur referances....

i need something more...

i want to display song name, singers like....in the player....if possible buffering time also....plz give me some suggestions...

Thanks..

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.