Forum Moderators: open

Message Too Old, No Replies

embed src so that it reads all song files in a dir?

embed src so that it reads all song files in a dir?

         

ryanc

3:13 pm on Jun 16, 2005 (gmt 0)

10+ Year Member


What would be the code to have a media player play every song in a directory and in order to skip to the next song you use the media player's controls?

Thanks,
ryanc

ryanc

3:30 pm on Jun 16, 2005 (gmt 0)

10+ Year Member


This is what I have now and it works fine, but I would like to have all the songs in one folder and have the player read all of those songs. That way when I upload a new song to the folder it will automatically read the new song.

function change(song)
{
embedStr="<embed src="+song+" type=application/x-mplayer2
pluginspage=http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/
autostart=true showcontrols=true showstatusbar=false showdisplay=false autorewind=true width=300 height=44>";
document.getElementById('player').innerHTML=embedStr;
}
</script>

<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/"
width="300" height="44" src="refineme.mp3" autostart="True" showcontrols="True" showstatusbar="false" showdisplay="False"
autorewind="True"></embed>

<SELECT name="songList" onChange="change(songList.value)">
<OPTION value="refineme.mp3">Refine Me</option>
<OPTION value="frostyeve.mp3">Frosty Eve</option>
<OPTION value="topten.mp3">Top Ten</option>
</SELECT>

Sathallrin

5:23 pm on Jun 16, 2005 (gmt 0)

10+ Year Member



If you can use PHP, you can populate your option list with all files in a dir like this:


<script>
function change(song)
{
embedStr="<embed src="+song+" type=application/x-mplayer2
pluginspage=http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/
autostart=true showcontrols=true showstatusbar=false showdisplay=false autorewind=true width=300 height=44>";
document.getElementById('player').innerHTML=embedStr;
}
</script>


<embed type="application/x-mplayer2" pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/"
width="300" height="44" src="refineme.mp3" autostart="True" showcontrols="True" showstatusbar="false" showdisplay="False"
autorewind="True"></embed>


<SELECT name="songList" onChange="change(songList.value)">
<?php
$path = "mp3s/";
$openDir = opendir ($path);
$files = array();
$dirs = array();


while($path = readdir($openDir)) {
if(is_dir($path)) array_push($dirs,$path);
else array_push($files,$path);
}
closedir ( $openDir );


sort($files);


foreach($files as $file) {
echo '<OPTION value="'.$path.$file.'">'.$file.'</option>'."\n";
}
?>
</SELECT>

Change the $path variable to the folder with your files.

ryanc

7:52 pm on Jun 16, 2005 (gmt 0)

10+ Year Member


Not sure why, but that is not working for some reason? I tried a few things, but kept getting errors?