Jump to content

Directory to Media Player Variable Please Help


Goodwin

Recommended Posts

Hiya,

I am wondering if anyone knows about any scripts out there that use all the mp3/wma in a selected directory and when clicked the chosen song is loaded up in a seperate frame in with this script in [b]<embed height=44 volume=-1 loop=true src=Selected URL in Here' width='310' autostart='true'></embed>[/b] i have been told i need it to be a variable in a PHP script.

Any Help will be great
Thanks
Danny
You can all files in a certain directory pretty simply using the opendir() and readdir() commands. Here's a good place to start:

http://us3.php.net/manual/fi/function.opendir.php

Once you have the gist of it, you can write another php script that displays your <embed> tag, and fills in the filename it was provided. Example from the manual (somewhat altered):

[code]<?php
$dir = "/some/directory/you/specify/";

// Open a known directory, and proceed to read its contents
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if(substr($file,0,1)!=".") {
$file_ext=end(explode(".",$file));
if($file_ext=="mp3" OR $file_ext=="wma") echo "<a href=\"embed.php?file="$file."\">".$file."</a><br />";
}
}
closedir($dh);
}
}
?>[/code]

that will create links like "embed.php?file=somefile.wmv".

next part [code]<?php
//embed.php
$dir = "/some/directory/you/specify/";
echo "<embed height=44 volume=-1 loop=true src='".$_GET['file']."' width='310' autostart='true'></embed>";
?>[/code]

keep in mind this is not your perfect world scenario, but a good shove in the right direction.
Here's another shove...I got a different take on your question than the guy above me...if you're asking how do you call a media player to queue up all the mp3s sitting in a directory, I did something similar by reading the directory, opening an m3u file, writing all the file names into the m3u and then passing the m3u filename to the media player - instant playlist based on the directory contents. I'd post code, but it was done as a mod to phpBB and is pretty involved.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.