Feb. 02, 2008iMran
Is it possible to automaticly generate playlists by listing all the reading the directory or a folder i set?
I think there is, but theres a few extra things I want added to it.
Can I make it display the latest tracks added at the top?
All my tracks end in [mysite.com].mp3
e.g. Some track - Some artist [mysite.com].mp3
Is it possible to take that bit out? So it only Some track - Some artist
Feb. 02, 2008AJAX
This playlist generator will sort your files by date with the newest first.
If you don't want some of the elements, such as <creator> just comment out (add 2 forward slashes to the line) or delete the line. Example - this will remove the creator element from the playlist: // echo " <creator>" . $creator . "</creator>\n";
To remove [mysite.com] from the Title, increase the 4 in this code to whatever value you need to remove all of [mysite.com]. Right now it's set to 4 to remove the extension .mp3. $title = substr($key, 0, strlen($key) - 4);
playlistlphp<?php
/*
* This is a sample file that reads through a directory, filters the mp3/jpg/flv
* files and builds a playlist from it. After looking through this file, you'll
* probably 'get the idea' and'll be able to setup your own directory.
*
*/
// set this to a creator name
$creator = "Myself";
// search for mp3 files. set this to '.flv' or '.jpg' for the other scripts
$filter = ".mp3";
// path to the directory you want to scan
// "./" = current directory
$directory = "./";
// URL to files
$url = "http://www.somesite.com";
/////////////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false))
{
$items[$entry]['mtime'] = filemtime($entry);
}
}
$d->close();
arsort($items);
}
// the playlist is built in an xspf format
// first, we'll add an xml header and the opening tags...
header("content-type:text/xml;charset=utf-8");
echo "<?xml version='1.0' encoding='utf-8'?>\n";
echo "<playlist version='1' xmlns='http://xspf.org/ns/0/'>\n";
echo " <title>Sample PHP Generated Playlist</title>\n";
echo " <info>" . $url . "</info>\n";
echo " <trackList>\n";
// ...then we loop through the array...
foreach($items as $key => $value)
{
$title = substr($key, 0, strlen($key) - 4);
echo " <track>\n";
echo " <creator>" . $creator . "</creator>\n";
echo " <title>" . $title . "</title>\n";
echo " <location>" . $url . '/' . $key . "</location>\n";
echo " <info>" . $url . "</info>\n";
echo " </track>\n";
}
// ...and last we add the closing tags
echo " </trackList>\n";
echo "</playlist>\n";
/*
* That's it! You can feed this playlist to the SWF by setting this as it's 'file'
* parameter in your HTML page.
*/
?>
Feb. 02, 2008iMran
Ok i did exactly what AJAX said but this is what I get when I go to the php_readdir_playlist.php page:
Warning: filemtime() [function.filemtime]: stat failed for Chris Jackson - You're So Sexy [iM1].mp3 in /home/immusicc/public_html/php_readdir_playlist.php on line 36
I get this repeated one below the other, its naming all the tracks with the error.
Im guessing by filemtime() it means something is wrong with the modified time?
Feb. 02, 2008iMran
[url=http://im1musicc.cs-webhost.com/php_readdir_playlist.php]Here[/url] is the link to my playlist, Could you tell me whats wrong?
Feb. 02, 2008AJAX
See: [url=http://www.php.net/function.filemtime]filemtime[/url]specifically:csnyder at chxo dot com
11-Aug-2006 08:59 for the fix...
Feb. 02, 2008Joe
Nice work, AJAX - code works great.
I'm pretty new at PHP and was wondering how you'd include multiple filetypes (say flv AND jpgs) into the same array?
Trying to get a playlist that will also include jpg thumbnails.
Feb. 03, 200859
Feb. 03, 2008AJAX
@Joe,
To get images for each track, name the images with the same filename as the media files (flv or mp3) but with an extension of jpg (or whatever image type you are using).
Then add the code in bold:foreach($items as $key => $value)
{
$title = substr($key, 0, strlen($key) - 4);
echo " <track>\n";
echo " <creator>" . $creator . "</creator>\n";
echo " <title>" . $title . "</title>\n";
echo " <location>" . $url . '/' . $key . "</location>\n";
echo " <image>" . $url . '/' . $title . ".jpg</image>\n";
echo " <info>" . $url . "</info>\n";
echo " </track>\n";
}
Feb. 03, 2008iMran
@AJAX
Nope im still getting the problem.
Heres the code im using
<?php
/*
* This is a sample file that reads through a directory, filters the mp3/jpg/flv
* files and builds a playlist from it. After looking through this file, you'll
* probably 'get the idea' and'll be able to setup your own directory.
*
*/
// set this to a creator name
$creator = "Myself";
// search for mp3 files. set this to '.flv' or '.jpg' for the other scripts
$filter = ".mp3";
// path to the directory you want to scan
// "./" = current directory
$directory = "./songs/08-january/";
// URL to files
$url = "http://im1music.net";
$mtime = exec ('stat -c %Y '. escapeshellarg ($path));
/////////////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false))
{
$items[$entry]['mtime'] = filemtime($entry);
}
}
$d->close();
arsort($items);
}
// the playlist is built in an xspf format
// first, we'll add an xml header and the opening tags
echo "<?xml version='1.0' encoding='utf-8'?>\n";
echo "<playlist version='1' xmlns='http://xspf.org/ns/0/'>\n";
echo " <title>Sample PHP Generated Playlist</title>\n";
echo " <info>" . $url . "</info>\n";
echo " <trackList>\n";
// ...then we loop through the array...
foreach($items as $key => $value)
{
$title = substr($key, 0, strlen($key) - 4);
echo " <track>\n";
echo " <creator>" . $creator . "</creator>\n";
echo " <title>" . $title . "</title>\n";
echo " <location>" . $url . '/' . $key . "</location>\n";
echo " <info>" . $url . "</info>\n";
echo " </track>\n";
}
// ...and last we add the closing tags
echo " </trackList>\n";
echo "</playlist>\n";
/*
* That's it! You can feed this playlist to the SWF by setting this as it's 'file'
* parameter in your HTML page.
*/
?>
I asked my file host and he said his using linux, so added the appropriate code. Maybe I put it in the wrong place?
Feb. 03, 2008AJAX
The line beginning with $mtime is in the wrong place and is using the wrong variable $path.
It should probably look like this (bold text):// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false))
{
$items[$entry]['mtime'] = exec ('stat -c %Y '. escapeshellarg ($entry));
}
}
$d->close();
arsort($items);
}
For testing, try this, call with your browser, and then if it's OK, remove or comment out these two lines (bold text):// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false))
{
$items[$entry]['mtime'] = exec ('stat -c %Y '. escapeshellarg ($entry));
$mtime = exec ('stat -c %Y '. escapeshellarg ($entry));
print "<pre>mtime: " . $mtime . "</pre>\n";
}
}
$d->close();
arsort($items);
}
Feb. 03, 2008iMran
I tried both of them but still not getting the results i want.
I put the code in the right place but click [url=http://im1musicc.cs-webhost.com/php_readdir_playlist.php]here[/url] to see what i get.
I also tried adding the extra two lines you gave but that doesnt work either, click [url=http://im1musicc.cs-webhost.com/php_readdir_playlist2.php]here[/url] to see it
Feb. 03, 2008AJAX
I don't have a Linux system to test against, but it appears that you're not getting the file stats.
You could try this:// read through the directory and filter files to an array and if you get an array of file information that looks like this:
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false))
{
print "<pre>"; print_r(stat($entry));
}
}
$d->close();
arsort($items);
}
Arraythen try this:
(
[0] => 2
[1] => 0
[2] => 33206
[3] => 1
[4] => 0
[5] => 0
[6] => 2
[7] => 6650147
[8] => 1201452190
[9] => 1184689538
[10] => 1184689623
[11] => -1
[12] => -1
[dev] => 2
[ino] => 0
[mode] => 33206
[nlink] => 1
[uid] => 0
[gid] => 0
[rdev] => 2
[size] => 6650147
[atime] => 1201452190
[mtime] => 1184689538
[ctime] => 1184689623
[blksize] => -1
[blocks] => -1
)
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false))
{
$stats = stat($entry);
$items[$entry]['mtime'] = $stats['mtime'];
}
}
$d->close();
arsort($items);
}
Feb. 03, 2008iMran
Nope that didnt work either :-(
I get a stat failed error. Check [url=http://im1musicc.cs-webhost.com/php_readdir_playlist3.php]here[/url]
Feb. 03, 2008AJAX
Is the file: Chris Jackson - You're So Sexy [iM1].mp3 actually residing in the directory: /home/immusicc/public_html/ ?
Maybe we need some path information before the filename.
print "<pre>"; print_r(stat('/home/immusicc/public_html/' . $entry));
Adjust /home/immusicc/public_html/ to be the full path to the MP3 files and see what results.
Feb. 03, 2008iMran
The path for the tracks are /home/im1musicc/public_html/songs/08-january/
I've change the file with that code and now I get the Array thing. Check [url=http://im1musicc.cs-webhost.com/php_readdir_playlist3.php]here[/url]
Feb. 03, 2008AJAX
So, it appears that the problem was the path.
Easiest thing would be to put the playlist generator script in the same directory as the MP3 files and use:$directory = "./";because the dir() function is only returning filenames, no path.
You might even be able to use filemtime() as in the original code.
Otherwise you have to add the path back on when you call filemtime():$items[$entry]['mtime'] = filemtime($directory . $entry);I guess the script should really be written this way to save some grief???
Feb. 03, 2008iMran
Heres the code I put in now
<?php
/*
* This is a sample file that reads through a directory, filters the mp3/jpg/flv
* files and builds a playlist from it. After looking through this file, you'll
* probably 'get the idea' and'll be able to setup your own directory.
*
*/
// set this to a creator name
$creator = "Myself";
// search for mp3 files. set this to '.flv' or '.jpg' for the other scripts
$filter = ".mp3";
// path to the directory you want to scan
// "./" = current directory
$directory = "./";
// URL to files
$url = "http://im1music.net";
/////////////////////////// no user configuration variables below this
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false))
{
$items[$entry]['mtime'] = exec ('stat -c %Y '. escapeshellarg ($entry));
}
}
$d->close();
arsort($items);
}
// the playlist is built in an xspf format
// first, we'll add an xml header and the opening tags
echo "<?xml version='1.0' encoding='utf-8'?>\n";
echo "<playlist version='1' xmlns='http://xspf.org/ns/0/'>\n";
echo " <title>Sample PHP Generated Playlist</title>\n";
echo " <info>" . $url . "</info>\n";
echo " <trackList>\n";
// ...then we loop through the array...
foreach($items as $key => $value)
{
$title = substr($key, 0, strlen($key) - 4);
echo " <track>\n";
echo " <creator>" . $creator . "</creator>\n";
echo " <title>" . $title . "</title>\n";
echo " <location>" . $url . '/' . $key . "</location>\n";
echo " <info>" . $url . "</info>\n";
echo " </track>\n";
}
// ...and last we add the closing tags
echo " </trackList>\n";
echo "</playlist>\n";
/*
* That's it! You can feed this playlist to the SWF by setting this as it's 'file'
* parameter in your HTML page.
*/
?>
Its in the same directory as the music files but it still doesnt work. Is it something im doing wrong?
[url=http://im1musicc.cs-webhost.com/songs/08-january/php_readdir_playlist.php]Here is the link[/url]
Feb. 03, 2008AJAX
Well, it's producing a playlist.
Is the problem that the files aren't sorted by newest first? If so, put a print array statement immediately after:arsort($items); and see if the array looks this:
}
print "<pre>; print_r($items); exit;Arrayindicating that you are getting the filemtime.
(
[Emma Burgess - All Songs.mp3] => Array
(
[mtime] => 1184689538
)
[songbig.mp3] => Array
(
[mtime] => 1184283681
)
Also, if the location URI:<location>http://im1music.net/Ryan Leslie - Somewhere Private [iM1].mp3</location>isn't right, just adjust the value of the $url variable.
Feb. 03, 2008iMran
I got it working! :-D
After one whole day if tweaking I got it to work! Thanks to you AJAX!
Now I just got one more question...
Is there a way I could make it play the playlist the opposite way? I want the last modified tracks at the bottom and the old ones at the top.
Thanks again AJAX! You dont know how much this has helped me!
Feb. 03, 2008AJAX
Just change:arsort($items); to asort($items); use:[url=http://us.php.net/manual/en/function.asort.php]PHP Manual[/url] to find all of the PHP functions, and their opposites.
Feb. 03, 2008iM1
Thanks AJAX
Feb. 06, 2008Rael
Hi i am trying to get this code working for me. i have created a website for the father in law for his pub. they have live entertainment wich we have been filming. i have managed to convert the AVI files in to FLV files and using the player on jeroenwijering.com have managed to get the movie to play online. i have used the wizzard to make a player with a playlist but thats as far as i can get. i would like to make a playlist of the movies one for each artist we have throughout the year.
here is what i have done so far.
i copied the code at the top of this page in to a notepad file and called it playlist.php
i changed the following
// set this to a creator name
$creator = "Myself";
// search for mp3 files. set this to '.flv' or '.jpg' for the other scripts
$filter = ".mp3";
// path to the directory you want to scan
// "./" = current directory
$directory = "./";
// URL to files
$url = "http://www.somesite.com";
to this
// set this to a creator name
$creator = "Rael Rigley";
// search for mp3 files. set this to '.flv' or '.jpg' for the other scripts
$filter = ".flv";
// path to the directory you want to scan
// "./" = current directory
$directory = "./artistvids/";
// URL to files
$url = "http://www.jessoparms.co.uk";
then uploaded it to the unix server. provided by Lowcostnames.co.uk
i open the location http://www.jessoparms.co.uk/artistvids/playlist.php
and receive the following displayed.
<?xml version="1.0" encoding="utf-8" ?>
- <playlist version="1" xmlns="http://xspf.org/ns/0/">
<title>Sample PHP Generated Playlist</title>
<info>http://www.jessoparms.co.uk</info>
<trackList />
</playlist>
i'm not entirley sure what i'm doing.
i have changed the HTML of my player to "play" the playlist.php file instead of the flv file. is this correct?
any help getting this working would be much apreciated.
many thanks
Rael
Feb. 06, 2008AJAX
It's probably just a small problem with the directory path. The easiest way to deploy this script is to put it with your media files and then use:$directory = "./";
However, you can also use a path that includes other directories. The way that you have it in your script, it will look for media files in "/artistvids/artistvids/" which probably doesn't exist. As noted in the comments, "./" means the current directory, which is "artistvids", then you are telling the script to look in a sub-directory of "artistvids", also named "artistvids". Probably not gonna work that way.
So use:$directory = "./";
If that doesn't work, post back here and we'll help you some more.
Feb. 06, 2008Rael
Thank you so much, you have gotten it working for me.
can i ask another question.
can i have a clickable list so people can choose what movie to play like the one on the main page of J W site.
if this is not posible with your PHP code then can i make the player control buttons bigger.
thank you once again for your help,
Rael
Feb. 06, 2008
To get a playlist below the player, add to the height of the video 20px for control bar + 23px for each track, then set displayheight to the height of your video.
So if your video is 320x240 and you want 3 tracks showing:
width=320
height=240+20+23*3=329
displayheight=240
Feb. 07, 2008Rael
Im sorry if i sound thick, but where would i do that.
im not too sure.
i made a few changes when i tired to do it and could no longer see the player.
i wondered if you could show me?
here is my page code
<embed src="http://www.jessoparms.co.uk/mediaplayer.swf" Width="470" height="300"
" allowscriptaccess="always" allowfullscreen="true"
flashvars="height=300&width=470&file=http://www.jessoparms.co.uk/artistvids/playlist.php
&image=http://www.jessoparms.co.uk/artistvids/player.png&backcolor=0x000000&frontcolor=0
x00FFFF&lightcolor=0xFF0000&screencolor=0x000000&showdownload=false&usefullscreen=true&t
humbsinplaylist=true" />
many thanks
Rael
Feb. 07, 2008
Assuming your video is 470x300 and you want a display area of that size, increasing the height to 435 and using a displayheight of 300 should show 5 playlist tracks.<embed src="http://www.jessoparms.co.uk/mediaplayer.swf" Width="470" height="435"
" allowscriptaccess="always" allowfullscreen="true"
flashvars="height=435&width=470&displayheight=300&file=http://www.jessoparms.co.uk/artistvids/playlist.php
&image=http://www.jessoparms.co.uk/artistvids/player.png&backcolor=0x000000&frontcolor=0
x00FFFF&lightcolor=0xFF0000&screencolor=0x000000&showdownload=false&usefullscreen=true&t
humbsinplaylist=true" />
Feb. 07, 2008MaestroJAL
Thanks AJAX for this script. I'm getting this error, though:
Sample PHP Generated Playlist http://www.infamousleucks.com/choirs/audio/temporary/ Warning: Invalid argument supplied for foreach() in /home/infamous/public_html/choirs/audio/temporary/playlist_generator.php on line 53
I had a few problems with the space character copying correctly when I made my php file from your code above. I replace all 250+ of them to get the script working. Apart from typing this all from hand (I'm very limited in time) is there some thing I missed or is there another corrupted character that may appear only in this part of the code and below? Thanks for your time.
Feb. 07, 2008MaestroJAL
Fixed it. I tried using an absolute path to for the current directory when I was troubleshooting the corrupted space character issue. Returned it to "./" and voila! It worked. Many, many thanks, AJAX. This will save me tons of time!
Feb. 07, 2008AJAX
@MaestroJAL,
Highlight, then copy & paste the code, then you shouldn't get those corrupted spaces. Otherwise, search [ALT+160] and replace [space] in your text editor.
Feb. 07, 2008MaestroJAL
Thanks AJAX. Funny thing, I did highlight and then copied and pasted the code. I used a "Find/Replace All" command for the spaces like you suggested. Cheers!
Feb. 16, 2008MaestroJAL
@AJAX,
How would I set this up to use .mp3 AND .flv? I tried using "!=" in the filter variable to choose everything BUT they few .php files in that folder. No go. I would also like to append the force_download.php to the info part of the playlist. Any ideas on that? Thanks in advance.
Feb. 16, 2008AJAX
Use:// search for mp3 files. set this to '.flv' or '.jpg' for the other scriptsand
$filter1 = ".mp3";
$filter2 = ".flv";while($entry = $d->read())
{
$ps1 = strpos(strtolower($entry), $filter1);
$ps2 = strpos(strtolower($entry), $filter2);
if (!(($ps2 === false) || ($ps2 === false)))
{
$items[$entry]['mtime'] = filemtime($entry);
}
}
For the download:// URL to filesand
$url = "http://www.somesite.com";
// Force Download Script
$fdl_script = "forcedownload.php?file="; // adjust as necessary, including path informationecho " <info>" . $url . '/' . $fdl_script . $key . "</info>\n";Should work. If not, post the output of the script (call it from your browser - View, Source so we can see the XML) and I'll tweak it.
Feb. 17, 2008MaestroJAL
@AJAX
Thanks, Ajax! Putting the code to work tonight. I'll let you know how it turns out.
Feb. 17, 2008MaestroJAL
@AJAX
I tried the changes. Here's what I received:
Parse error: syntax error, unexpected $end in /home/sgbanet/public_html/audio/cr2005/playlist_generator_2.php on line 75
http://www.sgba.net/audio/cr2005/playlist_generator_2.php
Now this particular folder only contains .mp3 files. Would looking for two kinds of files and finding only one break the code?
Feb. 17, 2008likethis
That error just means missing line ending ";" or mis-matched parenthesis somewhere at or above line 75. Post the entire playlist code and I'll have a look. Common programming error.
Feb. 17, 2008MaestroJAL
@likethis
Thanks for the response. I'm no programmer but I realized that the code was missing a "}" when I pasted the code and fixed it. Now I'm getting this:
2005 Couple's Retreat http://www.sgba.net/audio/cr2005/forcedownload.php?file= Warning: Invalid argument supplied for foreach() in /home/sgbanet/public_html/audio/cr2005/playlist_generator_2.php on line 55
Here's the code:
<?php
/*
* This is a sample file that reads through a directory, filters the mp3/jpg/flv
* files and builds a playlist from it. After looking through this file, you'll
* probably 'get the idea' and'll be able to setup your own directory.
*
*/
// set this to a creator name
$creator = "Dr. James Grier";
// search for mp3 files. set this to '.flv' or '.jpg' for the other scripts
$filter1 = ".mp3";
$filter2 = ".flv";
// path to the directory you want to scan
// "./" = current directory
$directory = "./";
// URL to files
$url = "http://www.sgba.net/audio/cr2005";
// Force Download Script
$fdl_script = "forcedownload.php?file="; // adjust as necessary, including path information
/////////////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps1 = strpos(strtolower($entry), $filter1);
$ps2 = strpos(strtolower($entry), $filter2);
if (!(($ps2 === false) || ($ps2 === false)))
{
$items[$entry]['mtime'] = filemtime($entry);
}
}
}
// the playlist is built in an xspf format
// first, we'll add an xml header and the opening tags...
header("content-type:text/xml;charset=utf-8");
echo "<?xml version='1.0' encoding='utf-8'?>\n";
echo "<playlist version='1' xmlns='http://xspf.org/ns/0/'>\n";
echo " <title>2005 Couple's Retreat</title>\n";
echo " <info>" . $url . '/' . $fdl_script . $key . "</info>\n";
echo " <trackList>\n";
// ...then we loop through the array...
foreach($items as $key => $value)
{
$title = substr($key, 0, strlen($key) - 4);
echo " <track>\n";
echo " <creator>" . $creator . "</creator>\n";
echo " <title>" . $title . "</title>\n";
echo " <location>" . $url . '/' . $key . "</location>\n";
echo " <info>" . $url . "</info>\n";
echo " </track>\n";
}
// ...and last we add the closing tags
echo " </trackList>\n";
echo "</playlist>\n";
/*
* That's it! You can feed this playlist to the SWF by setting this as it's 'file'
* parameter in your HTML page.
*/
?>
Feb. 17, 2008MaestroJAL
After looking closely at what I replaced, I added
$d->close();
arsort($items);
}
after the "while" code. Now I get this:
<br />
<b>Warning</b>: arsort() expects parameter 1 to be array, null given in <b>/home/sgbanet/public_html/audio/cr2005/playlist_generator_2.php</b> on line <b>43</b><br />
<br />
<b>Warning</b>: Cannot modify header information - headers already sent by (output started at /home/sgbanet/public_html/audio/cr2005/playlist_generator_2.php:43) in <b>/home/sgbanet/public_html/audio/cr2005/playlist_generator_2.php</b> on line <b>48</b><br />
<?xml version='1.0' encoding='utf-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>2005 Couple's Retreat</title>
<info>http://www.sgba.net/audio/cr2005</info>
<trackList>
<br />
<b>Warning</b>: Invalid argument supplied for foreach() in <b>/home/sgbanet/public_html/audio/cr2005/playlist_generator_2.php</b> on line <b>57</b><br />
</trackList>
</playlist>
Feb. 18, 2008fetterov
i got the playlist.php to work, but the playlist doesnt show up in the page. the files do play.
Feb. 18, 2008fetterov
can anyone help?
Feb. 18, 2008AJAX
@MasestroJAL,
This:<?phpresults in this (my video files):
/*
* This is a sample file that reads through a directory, filters the mp3/jpg/flv
* files and builds a playlist from it. After looking through this file, you'll
* probably 'get the idea' and'll be able to setup your own directory.
*
*/
// set this to a creator name
$creator = "Dr. James Grier";
// search for mp3 files. set this to '.flv' or '.jpg' for the other scripts
$filter1 = ".mp3";
$filter2 = ".flv";
// path to the directory you want to scan
// "./" = current directory
$directory = "./";
// URL to files
$url = "http://www.sgba.net/audio/cr2005";
// Force Download Script
$fdl_script = "forcedownload.php?file="; // adjust as necessary, including path information
/////////////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps1 = strpos(strtolower($entry), $filter1);
$ps2 = strpos(strtolower($entry), $filter2);
if (!(($ps2 === false) || ($ps2 === false)))
{
$items[$entry]['mtime'] = filemtime($entry);
}
}
$d->close();
arsort($items);
}
// the playlist is built in an xspf format
// first, we'll add an xml header and the opening tags...
header("content-type:text/xml;charset=utf-8");
echo "<?xml version='1.0' encoding='utf-8'?>\n";
echo "<playlist version='1' xmlns='http://xspf.org/ns/0/'>\n";
echo " <title>2005 Couple's Retreat</title>\n";
echo " <trackList>\n";
// ...then we loop through the array...
foreach($items as $key => $value)
{
$title = substr($key, 0, strlen($key) - 4);
echo " <track>\n";
echo " <creator>" . $creator . "</creator>\n";
echo " <title>" . $title . "</title>\n";
echo " <location>" . $url . '/' . $key . "</location>\n";
echo " <info>" . $url . '/' . $fdl_script . $key . "</info>\n";
echo " </track>\n";
}
// ...and last we add the closing tags
echo " </trackList>\n";
echo "</playlist>\n";
/*
* That's it! You can feed this playlist to the SWF by setting this as it's 'file'
* parameter in your HTML page.
*/
?><?xml version='1.0' encoding='utf-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>2005 Couple's Retreat</title>
<trackList>
<track>
<creator>Dr. James Grier</creator>
<title>flash101_test_new_wmd</title>
<location>http://www.sgba.net/audio/cr2005/flash101_test_new_wmd.flv</location>
<info>http://www.sgba.net/audio/cr2005/forcedownload.php?file=flash101_test_new_wmd.flv</info>
</track>
<track>
<creator>Dr. James Grier</creator>
<title>flash101_test_new</title>
<location>http://www.sgba.net/audio/cr2005/flash101_test_new.flv</location>
<info>http://www.sgba.net/audio/cr2005/forcedownload.php?file=flash101_test_new.flv</info>
</track>
...!...!...
<track>
<creator>Dr. James Grier</creator>
<title>video_100</title>
<location>http://www.sgba.net/audio/cr2005/video_100.flv</location>
<info>http://www.sgba.net/audio/cr2005/forcedownload.php?file=video_100.flv</info>
</track>
<track>
<creator>Dr. James Grier</creator>
<title>stream_dur_test-1</title>
<location>http://www.sgba.net/audio/cr2005/stream_dur_test-1.flv</location>
<info>http://www.sgba.net/audio/cr2005/forcedownload.php?file=stream_dur_test-1.flv</info>
</track>
</trackList>
</playlist>
Feb. 18, 2008AJAX
@MaestroJAL,
I think the forcedownload script has to be one directory up from the files. Is that the correct path in the playlist?
Feb. 18, 2008AJAX
@fetterov,
Do you mean that there are not playlist tracks displayed below the player?
To get them to show, make height = displayheight + 20 + (23 * tracks) or (41 * tracks) if you are using thumbnails in the playlist.
So if your video is 320x240 and you want 4 tracks:
height=240 + 20 + (23 * 4 ) = 352
width=320
displayheight=240
Feb. 18, 2008MaestroJAL
@AJAX
I'm being a pest, I know. Sorry, but this is working out WAY too good for the site I administer so I'm going to ask for some more. How can I have the playlist generator sort the playlist alphabetically? The order is always consistent but sometimes it's backwards (http://www.sgba.net/grace_news/index.php) and sometimes it's just plain out of order (http://www.sgba.net/media/index.php). Ideas? Above all, thanks for the tremendous help on this script!
@fetterov
How are you calling for the file "playlist.php"? I'm not a tech guru by any stretch of the imagination, but I have this working on my sites so I'll try to help.
Feb. 18, 2008MaestroJAL
@AJAX
We must have been typing at the same time. I'll compare the code you gave me to what I have on the server. Thanks again!
Feb. 18, 2008AJAX
See: [url=http://us2.php.net/arsort]arsort[/url] for all of your PHP needs.
arsort() is reverse sort for newest by mtime first.
asort() will give you oldest first.
shuffle() will mix'em up.
Feb. 27, 2008jay
hi guys,
i just tried the script and i works fine.
but - there is a problem with the filter1 - the script ignores the first filter filetype and only generates a playlist for the filetype in filter2.
can some one tell me how to fix this.
greetz,
jay
Feb. 27, 2008jay
now i got it - just added:
$ps1 = strpos(strtolower($entry), $filter1);
if (!(($ps1 === false) || ($ps1 === false)))
{
$items[$entry]['mtime'] = filemtime($entry);
}
Mar. 04, 2008mike
hi,
i like to shuffle my playlist, but shuffle($items); only gives me numbers back.
any hint for me?
Mar. 04, 2008AJAX
Put this function at the end of the code, just before the closing tag. Then call shuffle_assoc($items); to shuffle the playlist.function shuffle_assoc(&$array)
{
if (count($array)>1)
{
$keys = array_rand($array, count($array));
foreach($keys as $key)
{
$new[$key] = $array[$key];
$array = $new;
}
return true;
}
}
Mar. 04, 2008mike
great - works fine now. :-)
many thanx.
Mar. 05, 2008CSiPet
How can I delete the playlist number before the tracktitle? So I would like only one row for one item!
Oh, and I would like to deactivate the small play button next to the title in the playlist! Is it possible?
THX
Mar. 05, 2008jazzie
You can get rid of the number by putting a non-breaking space in the creator element of your playlist.<creator> </creator> Enter a non-breaking space with ALT+0160 (hold the ALT key and type 0160 on the number pad).
You can never get rid of the colon.
To get a one row playlist, put thumbsinplaylist=false in your flashvars.
To deactivate the download icon (the circumscribed triangle), remove the info element from your playlist.
Mar. 05, 2008CSiPet
Perfect! Everithing fine. THX
Mar. 09, 2008dwmccoy
@AJAX
Is there a way to sort the list alphabetically or numerically? The asort and arsort appear to only sort by date. I'm no PHP programmer by any means. Any help would be appreciated.
thanks
Mar. 09, 2008AJAX
The whole point of this playlist generator was to show the newest items in a directory first.
Find this:$items[$entry]['mtime'] = filemtime($entry);replace it with this:$items[] = $entry;
Find this:arsort($items);replace it with this:sort($items);
Find this:foreach($items as $key => $value)replace it with this:
{
$title = substr($key, 0, strlen($key) - 4);
echo " <track>\n";
echo " <creator>" . $creator . "</creator>\n";
echo " <title>" . $title . "</title>\n";
echo " <location>" . $url . '/' . $key . "</location>\n";
echo " <info>" . $url . '/' . $fdl_script . $key . "</info>\n";
echo " </track>\n";
}foreach($items as $value)and it should be broken.
{
$title = substr($value, 0, strlen($value) - 4);
echo " <track>\n";
echo " <creator>" . $creator . "</creator>\n";
echo " <title>" . $title . "</title>\n";
echo " <location>" . $url . '/' . $value . "</location>\n";
echo " <info>" . $url . '/' . $fdl_script . $value . "</info>\n";
echo " </track>\n";
}
Mar. 10, 2008dwmccoy
@AJAX
Thank you very much! Your the best!
Mar. 11, 2008musketir
Hi AJAX
1st
I like to make automated playlist like this but don't work!
When my site it's open all time it's on working but nothing to see.
Here it's the link to my site www.zupapotocani.ch/index3.php
2nd
How it's possible to bring the player to play in original size, I mean some video have width of 300px and some 500px?
Thank you.
Mar. 11, 2008AJAX
Put your [url=http://www.zupapotocani.ch/multimedija/video_playlist.php]playlist URI[/url] in your browser and this is what you get back:<?xml version='1.0' encoding='utf-8'?>Probably because you have the directory set wrong here:
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>Sample PHP Generated Playlist</title>
<info>http://www.zupapotocani.ch/multimedija/video</info>
<trackList>
<br />
<b>Warning</b>: Invalid argument supplied for foreach() in <b>/var/www/vhosts/zupapotocani.ch/httpdocs/multimedija/video_playlist.php</b> on line <b>53</b><br />
</trackList>
</playlist>
// path to the directory you want to scanIf the script is in the same directory as your video files, then current directory "./" is correct. If the script is one directory above your video files, then something like "./videos/" would be correct.
// "./" = current directory
$directory = "./";
To play the video in the original size, use:so.addVariable('overstretch','none'); and make sure that your display area is big enough for the video.
Mar. 12, 2008musketir
Thank you AJAX but now it's only a xml list without thumbs like this player on your site http://www.jeroenwijering.com/?item=JW_FLV_Media_Player
I will the same for my site like this on your site. Which code do you have in your site? Can you send my per email webmaster@zupapotocani.ch or put in here?
Thanks
Mar. 12, 2008AJAX
@musketir,
The script can easily be modified to include images, but there must be some correspondence between the video file name and the image file name, such as:video_file_01.flvor
image_file_01.jpgMy_Birthday.flv
My_Birthday.jpg
May. 06, 2008MaestroJAL
@AJAX
Thanks for all the help on this script. I have used versions of this script all over sites I administer (has made my life MUCH easier). I have a question. Is it possible to build separate versions of the tracks based on the kind of file being evaluated?
Again, much thanks!
May. 06, 2008MaestroJAL
I'm getting a very weird issue when using this code I modified to create javascript links based off of the $title. IE reports that the file is invalid because the <info> element ends with </track> not </info>. Navigator and Safari both dynamically fix the issue, I believe. Here's the code I modified:
$title = substr($key, 0, strlen($key) - 4);
echo " <track>\n";
echo " <creator>" . $creator . "</creator>\n";
echo " <title>" . $title . "</title>\n";
echo " <location>" . $url . '/' . $key . "</location>\n";
echo " <info>javascript:loadPlaylist('http://www.sgba.net/conferences/" . $title . "/playlist.php')</info>\n";
echo " </track>\n";
The actual playlist file can be called here:
http://www.sgba.net/images/series/series_nav.php
Any help in this rather defunct thread would be greatly appreciated!
May. 07, 2008positionMarker
Usually wrapping the element data in a CDATA tag will fix the issue.echo " <info><![CDATA[javascript:loadPlaylist('http://www.sgba.net/conferences/" . $title . "/playlist.php')]]></info>\n";
May. 07, 2008MaestroJAL
Thanks, positionMarker! Worked like a charm!
May. 11, 2008MaestroJAL
@AJAX
I reiterate my second question above. Is there a way to build different tracks based on file extension? The script addresses 95% of my needs. I'm looking for that 5% more! Thanks!
May. 11, 2008positionMarker
@MaestroJAL
Is there a way to build different tracks based on file extension?Can you elaborate a bit on "different tracks"?
Different in what way? I don't understand what you want.
May. 11, 2008MaestroJAL
@positionMarker
Thanks for the help. Here's my issue: I have folders that usually contain both .mp3 and .flv files. I'd like to construct different track information (as it passes through the array (maybe another array?)) like image or download link, etc. based on wether the file is an .mp3 file or a .flv file.
Example:
For an .mp3 file I'd like something like this in the trackList:
<track>
<creator>Audio</creator>
<location>http://www.thornvillechurch.com/sermons/tt/Worship Words - Audio.mp3</location>
<info>http://www.thornvillechurch.com/sermons/tt/force_download?file=Worship Words - Audio.mp3</info>
<image>http://www.thornvillechurch.com/images/series/tt.png</image>
</track>
While for a .flv file (in the same folder) I'd like the track information that's automatically written to change to this:
<track>
<creator>Video</creator>
<location>http://www.thornvillechurch.com/sermons/tt/Worship Words - Video.flv</location>
<info>http://www.thornvillechurch.com/messages/index.php</info>
<image>http://www.thornvillechurch.com/images/series/tt.png</image>
</track>
I was thinking the script may be able to delineate and write track information based on the file's extension (either .mp3 or .flv).
May. 18, 2008MaestroJAL
Bump. Anyone?
May. 18, 2008positionMarker
Rather than me wasting a bunch of time trying to guess exactly what your code looks like, post the whole script.
Then it should be very easy to create the different tracks that you want.
May. 18, 2008positionMarker
<?php
// read through a directory, filter by mp3/jpg/flv and build an XSPF playlist
// search for mp3 and flv files.
$filter1 = 'mp3';
$filter2 = 'flv';
// path to the directory you want to scan
// './' = current directory
$directory = './';
// URLs to files
$base_url = 'http://www.thornvillechurch.com/';
$files = 'sermons/tt/';
$images = 'images/series/tt.png';
// Force Download Script
$fdl_script = 'forcedownload.php?file='; // adjust as necessary, including path information
/////////////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps1 = strpos(strtolower($entry), $filter1);
$ps2 = strpos(strtolower($entry), $filter2);
if (!(($ps1 === false) && ($ps2 === false)))
{
$items[$entry]['mtime'] = filemtime($entry);
}
}
$d->close();
arsort($items);
}
// xml header and opening tags...
header("content-type:text/xml;charset=utf-8");
print <<<END
<?xml version='1.0' encoding='utf-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>2005 Couple's Retreat</title>
<trackList>
END;
// loop through the array
foreach($items as $key => $value)
{
$type = substr($key, strlen($key) - 3);
print " <track>\n";
if($type == 'mp3')
{
print " <creator>Audio</creator>\n";
print " <info>" . $base_url . $files . $fdl_script . $key . "</info>\n";
}
else
{
print " <creator>Video</creator>\n";
print " <info>" . $base_url . "messages/index.php</info>\n";
}
print <<<END
<location>$base_url$files$key</location>
<image>$base_url$images</image>
</track>
END;
}
// closing tags
print <<<END
</trackList>
</playlist>
END;
?>
May. 19, 2008MaestroJAL
@ positionMarker
Many, many thanks! I'll put this to work in a few hours. I am assuming that you used the code I posted above. Again, thank you!
May. 19, 2008positionMarker
@MaestroJAL,
Yeah, I used the code posted above on 18.02.2008.
The really funny thing is, I fixed two mistakes in that code. The code as posted does not select MP3 and FLV.
So, if you're using that code elsewhere, find this:if (!(($ps2 === false) || ($ps2 === false)))and change it to this:
if (!(($ps1 === false) && ($ps2 === false)))
May. 19, 2008MaestroJAL
@positionMarker
Through all the changes I made in this script, I actually saw that you fixed this but only after I tweaked it back incorrectly. This works great and I believe I actually learned a little PHP too. Again, many thanks!
May. 19, 2008positionMarker
@MaestroJAL,
You're welcome and good luck
May. 22, 2008Philman
I want to put in my playlist :
- image (first image of a xxx.flv file)
- title followed by file-weight if possible
- creator
How can i do it ?
i need only the final xml form :
<track>
<image>.......
<title>......
<file-weght>.....
<creator>......
<info>....
</track>
...and so one....
Also : What is the code for the form "forcedownload.php" itself ?
Note : i'm french
Bests regards
May. 22, 2008MaestroJAL
I can only answer the second request. The "forcedownload.php" should actually be "force_download.php" and is bundled with the JW players. It allows you to force a download of a file (like an .mp3) that would normally be played by the browser.
May. 22, 2008Philman
Thanks for your help. But i want propose complete choice between JW player or/and download. In this occurence can i still use force_download.php ? Moreover force_download.php seem not present as a file into the JW player's bundle. Is it always at http://www.sgba.net/audio/cr2005/forcedownload.php and have same path for video player ?
May. 22, 2008MaestroJAL
@Philman
The "force_download.php" file used to be included. It needs to be placed in the folder that contains the media to be downloaded. It does not have to be in the same folder as your player. Here's the thread with the file (and a great deal of help on using the script):
http://www.jeroenwijering.com/?thread=8883
If you're asking if you can offer your visitors a choice about which way they would like to access your media (either the JW player or direct download), you can set up the player to force the download of the media when the download link is clicked by using the "force_download.php" script. That way they can use the player to listen or simply download the file to their machine. In your playlist you would need to include the <info> tags and have them configured to point to the "force_download.php" script. Example:
<info>http://www.your_server.com/folder_containing_media_files_and_force_download_script/force_download.php?file=file_to_be_downloaded.mp3
Hope this is helpful. If not, there are MANY more people that know more than I about such things. I just know what works for me and my sites and I have a lot of gratitude for those who offer their skills here.
May. 22, 2008Philman
Many thanks for your answer ! Actually 4:30 AM in France and I go to bed and tomorrow I will test all that...
May. 23, 2008Philman
@MaestroJAL
You can view result at http://www.rmc71.com/Videos.htm
However Videos are not playing ! Yet files.flv and other (html, xml, php) are in the same folder : public_html and i use force_download for flv files. Note the pictures are loaded directly in JPG format (not extracted from flv files, in the playlist.xml).
Where is the mistake ?...
May. 23, 2008andersen
@Philman - when i paste the video urls from your playlist into the browser address line they return a "404 file not found"
this could indicate the MIME problem - from the page- http://www.jeroenwijering.com/?item=JW_FLV_Media_Player If FLV playback doesn't work on your site which runs off an IIS server, the FLV mimetype isn't added to the server.
Please contact your webserver administrator on this
(if you're an admin, here's how to fix it - http://www.adobe.com/cfusion/knowledgebase/index.cfm?id=tn_19439 ).
May. 23, 2008Philman
@MaestroJAL
I apologize ! it's my own fault (little error in flv path) All is now correct.
Many many thanks for your help !
May. 23, 2008Philman
@andersen
Sorry I had don't view your text before my last post. There is no MIME problem, it was my own problem ;-)
Regards
May. 26, 2008Tony L
I wonder it's possible to have the timestamp from each file shown in the <title> tag - could someone help with with the solution to this one if there is any.
Tony
May. 27, 2008nickName
If you are using one of the playlist generators posted above, in which filemtime is being retrieved, simply format the time and place it in the title element.
Format time:$time = date("H:i:s", $value['mtime']);Refer to this page for formatting codes: http://www.php.net/manual/en/function.date.php
Place the time within the appropriate print code: print <<<END
<track>
<creator>Video $time</creator>
<info>{$base_url}messages/index.php</info>
<location>$base_url$files$key</location>
<image>$base_url$images</image>
</track>
END;
May. 27, 2008Tony L
Thanks for the quick response to my query - however it produces the same time for every file:
<title>Action News 36 Webcast</title>
−
<trackList>
−
<track>
<creator>Action News 36 Webcast</creator>
<title>Wednesday December 31st 1969, 7:00 pm</title>
−
<location>
http://xxxxxx/media/video/webcast/080526_eveningwebcast.flv
</location>
<image>http://xxxxxx/media/images/webcast.png</image>
</track>
Any ideas on how this script can be modified to produce the correct timestamp for each file?
Thanks in advance,
Tony
May. 27, 2008nickName
I probably should have mentioned that:$time = date("H:i:s", $value['mtime']);should be put in the foreach() loop, right after either:$title = substr($key, 0, strlen($key) - 4);or$type = substr($key, strlen($key) - 3);depending on the exact version, of the playlists posted, that above you are using.
May. 27, 2008Tony L
Thanks again for that response, but the result was still the same.
Here's the code with the additional time array:
<?php
// read through a directory, filter by mp3/jpg/flv and build an XSPF playlist
// set this to a creator name
$creator1 = "Action News 36";
$creator2 = "Webcast";
// search for mp3 and flv files.
$filter1 = 'mp3';
$filter2 = 'flv';
// path to the directory you want to scan
// './' = current directory
$directory = "../media/video/webcast/";
// URLs to files
$base_url = 'http://xx.xxx.xxx.xx/';
$files = 'media/video/webcast/';
$images = 'media/images/webcast.png';
// Force Download Script
$fdl_script = 'forcedownload.php?file='; // adjust as necessary, including path information
/////////////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps1 = strpos(strtolower($entry), $filter1);
$ps2 = strpos(strtolower($entry), $filter2);
if (!(($ps1 === false) && ($ps2 === false)))
{
$items[$entry]['mtime'] = filemtime($entry);
}
}
$d->close();
arsort($items);
}
// xml header and opening tags...
header("content-type:text/xml;charset=utf-8");
print <<<END
<?xml version='1.0' encoding='utf-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>Action News 36 Webcast</title>
<trackList>
END;
// loop through the array
foreach($items as $key => $value)
{
$type = substr($key, strlen($key) - 3);
$time = date("m/d/y - g:i a", $value['mtime']);
print " <track>\n";
{
print " <creator>" . $creator1 . " " . $creator2 ."</creator>\n";
}
print <<<END
<title>$time</title>
<location>$base_url$files$key</location>
<image>$base_url$images</image>
</track>
END;
}
// closing tags
print <<<END
</trackList>
</playlist>
END;
?>
which produces this
<?xml version='1.0' encoding='utf-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>Action News 36 Webcast</title>
<trackList>
<track>
<creator>Action News 36 Webcast</creator>
<title>12/31/69 - 7:00 pm</title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/080526_eveningwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>12/31/69 - 7:00 pm</title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/080527_afternoonwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>12/31/69 - 7:00 pm</title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/080527_morningwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>12/31/69 - 7:00 pm</title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/082305_eveningwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>12/31/69 - 7:00 pm</title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/080522_eveningwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>12/31/69 - 7:00 pm</title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/080524_eveningwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>12/31/69 - 7:00 pm</title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/080526_afternoonwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>12/31/69 - 7:00 pm</title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/080525_eveningwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>12/31/69 - 7:00 pm</title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/080526_morningwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>12/31/69 - 7:00 pm</title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/080523_afternoonwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
</trackList>
</playlist>
I've even tried using filectime and fileatime to see if it would create a different response, but to no avail.
Any help on this would be greatly appreciated.
Tony
May. 27, 2008nickName
I cleaned up a couple of stray brackets and put a print statement after arsort() for debugging.
Call this script from your browser and you should get an array that looks like this:<pre>ArrayIf you don't have the mtime, then there is something wrong with the filemtime() function.
(
[YouTubeAlex OLoughlinOnSetInterview.flv] => Array
(
[mtime] => 1208055869
)
[flash101_test_new_wmd.flv] => Array
(
[mtime] => 1202277200
)
[flash101_test_new.flv] => Array
(
[mtime] => 1202277103
)
See this post (look up a few posts for the errors): http://www.jeroenwijering.com/?thread=9581#msg56880
<?php
// read through a directory, filter by mp3/jpg/flv and build an XSPF playlist
// set this to a creator name
$creator1 = "Action News 36";
$creator2 = "Webcast";
// search for mp3 and flv files.
$filter1 = 'mp3';
$filter2 = 'flv';
// path to the directory you want to scan
// './' = current directory
$directory = "../media/video/webcast/";
// URLs to files
$base_url = 'http://xx.xxx.xxx.xx/';
$files = 'media/video/webcast/';
$images = 'media/images/webcast.png';
// Force Download Script
$fdl_script = 'forcedownload.php?file='; // adjust as necessary, including path information
/////////////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps1 = strpos(strtolower($entry), $filter1);
$ps2 = strpos(strtolower($entry), $filter2);
if (!(($ps1 === false) && ($ps2 === false)))
{
$items[$entry]['mtime'] = filemtime($entry);
}
}
$d->close();
arsort($items);
}
print "<pre>"; print_r($items); exit;
// xml header and opening tags...
header("content-type:text/xml;charset=utf-8");
print <<<END
<?xml version='1.0' encoding='utf-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>Action News 36 Webcast</title>
<trackList>
END;
// loop through the array
foreach($items as $key => $value)
{
$type = substr($key, strlen($key) - 3);
$time = date("m/d/y - g:i a", $value['mtime']);
print <<<END
<track>
<creator>$creator1 $creator2</creator>
<title>$time</title>
<location>$base_url$files$key</location>
<image>$base_url$images</image>
</track>
END;
}
// closing tags
print <<<END
</trackList>
</playlist>
END;
?>
May. 28, 2008Tony L
Thank you nickName - I think whe are at least getting closer to the solution, if not the real route of the problems with this playlist....
I called up the script in it produced this response:
<pre>Array
(
[080527_afternoonwebcast.flv] => Array
(
[mtime] =>
)
[080526_eveningwebcast.flv] => Array
(
[mtime] =>
)
[080528_morningwebcast.flv] => Array
(
[mtime] =>
)
[080527_morningwebcast.flv] => Array
(
[mtime] =>
)
[082305_eveningwebcast.flv] => Array
(
[mtime] =>
)
[080522_eveningwebcast.flv] => Array
(
[mtime] =>
)
[080524_eveningwebcast.flv] => Array
(
[mtime] =>
)
[080526_afternoonwebcast.flv] => Array
(
[mtime] =>
)
[080525_eveningwebcast.flv] => Array
(
[mtime] =>
)
[080526_morningwebcast.flv] => Array
(
[mtime] =>
)
[080527_eveningwebcast.flv] => Array
(
[mtime] =>
)
[080523_afternoonwebcast.flv] => Array
(
[mtime] =>
)
)
Taking your modifications to the playlist plus the filemtime workaround as prescribed by csnyder at chxo dot com on the php.net site into consideration, the script looks like this:
<?php
// read through a directory, filter by mp3/jpg/flv and build an XSPF playlist
// set this to a creator name
$creator1 = "Action News 36";
$creator2 = "Webcast";
// search for mp3 and flv files.
$filter1 = 'mp3';
$filter2 = 'flv';
// path to the directory you want to scan
// './' = current directory
$directory = "../media/video/webcast/";
// URLs to files
$base_url = 'http://xx.xxx.xxx.xx/';
$files = 'media/video/webcast/';
$images = 'media/images/webcast.png';
// Force Download Script
$fdl_script = 'forcedownload.php?file='; // adjust as necessary, including path information
$mtime = exec ('stat -c %Y '. escapeshellarg ($directory));
/////////////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps1 = strpos(strtolower($entry), $filter1);
$ps2 = strpos(strtolower($entry), $filter2);
if (!(($ps1 === false) && ($ps2 === false)))
{
$items[$entry][$mtime] = filemtime($entry);
}
}
$d->close();
arsort($items);
}
print "<pre>"; print_r($items); exit;
// xml header and opening tags...
header("content-type:text/xml;charset=utf-8");
print <<<END
<?xml version='1.0' encoding='utf-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>Action News 36 Webcast</title>
<trackList>
END;
// loop through the array
foreach($items as $key => $value)
{
$type = substr($key, strlen($key) - 3);
$time = date("m/d/y - g:i a", $value[$mtime]);
print <<<END
<track>
<creator>$creator1 $creator2</creator>
<title>$time</title>
<location>$base_url$files$key</location>
<image>$base_url$images</image>
</track>
END;
}
// closing tags
print <<<END
</trackList>
</playlist>
END;
?>
which produces this:
<pre>Array
(
[080527_afternoonwebcast.flv] => Array
(
[1211974995] =>
)
[080526_eveningwebcast.flv] => Array
(
[1211974995] =>
)
[080528_morningwebcast.flv] => Array
(
[1211974995] =>
)
[080527_morningwebcast.flv] => Array
(
[1211974995] =>
)
[082305_eveningwebcast.flv] => Array
(
[1211974995] =>
)
[080522_eveningwebcast.flv] => Array
(
[1211974995] =>
)
[080524_eveningwebcast.flv] => Array
(
[1211974995] =>
)
[080526_afternoonwebcast.flv] => Array
(
[1211974995] =>
)
[080525_eveningwebcast.flv] => Array
(
[1211974995] =>
)
[080526_morningwebcast.flv] => Array
(
[1211974995] =>
)
[080527_eveningwebcast.flv] => Array
(
[1211974995] =>
)
[080523_afternoonwebcast.flv] => Array
(
[1211974995] =>
)
)
I thank you again for helping out with this and hopefully a successful solution can be found - even if it traces down to something with the server's PHP config.
Tony L
May. 28, 2008nickName
Great progress!
The exec() is working, so you just need to move it to the correct place.
Delete this line of code:$mtime = exec ('stat -c %Y '. escapeshellarg ($directory));
Then, change this code:$items[$entry][$mtime] = filemtime($entry);to this:$items[$entry][$mtime] = exec('stat -c %Y ' . escapeshellarg($entry));so that the filemtime for each individual file is being retrieved and put into the array. That should do it!
Also, you could change these three lines of code:$ps1 = strpos(strtolower($entry), $filter1);to this one line:
$ps2 = strpos(strtolower($entry), $filter2);
if (!(($ps1 === false) && ($ps2 === false)))if(($filter1 == substr(strtolower($entry), strlen($entry) - 3)) || ($filter2 == substr(strtolower($entry), strlen($entry) - 3)))This change just saves getting files that have flv or mp3 somewhere in their filename, but not as the extension. I would make the filemtime change first, then when that is working, make this change. It's not mandatory, just better code.
May. 28, 2008Tony L
We are getting closer to the solution here...
Having incorporated the changes above with some slight modification to produce the playlist in the right format, here's what the new version of the script looks like:
<?php
// read through a directory, filter by mp3/jpg/flv and build an XSPF playlist
// set this to a creator name
$creator1 = "Action News 36";
$creator2 = "Webcast";
// search for mp3 and flv files.
$filter1 = 'flv';
// path to the directory you want to scan
// './' = current directory
$directory = "../media/video/webcast/";
// URLs to files
$base_url = 'http://xx.xxx.xxx.xx/';
$files = 'media/video/webcast/';
$images = 'media/images/webcast.png';
// Force Download Script
$fdl_script = 'forcedownload.php?file='; // adjust as necessary, including path information
/////////////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
if(($filter1 == substr(strtolower($entry), strlen($entry) - 3)))
{
$items[$entry][$mtime] = exec('stat -c %Y ' . escapeshellarg($directory));
}
}
$d->close();
arsort($items);
}
// xml header and opening tags...
header("content-type:text/xml;charset=utf-8");
print <<<END
<?xml version='1.0' encoding='utf-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>Action News 36 Webcast</title>
<trackList>
END;
// loop through the array
foreach($items as $key => $value)
{
$type = substr($key, strlen($key) - 3);
$time = date("m/d/y - g:i a", $value[$mtime]);
print <<<END
<track>
<creator>$creator1 $creator2</creator>
<title>$time</title>
<location>$base_url$files$key</location>
<image>$base_url$images</image>
</track>
END;
}
// closing tags
print <<<END
</trackList>
</playlist>
END;
?>
Which produces this:
<?xml version='1.0' encoding='utf-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>Action News 36 Webcast</title>
<trackList>
<track>
<creator>Action News 36 Webcast</creator>
<title>05/28/08 - 11:36 am</title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/080527_afternoonwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>05/28/08 - 11:36 am</title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/080526_eveningwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>05/28/08 - 11:36 am</title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/080528_morningwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>05/28/08 - 11:36 am</title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/080527_morningwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>05/28/08 - 11:36 am</title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/082305_eveningwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>05/28/08 - 11:36 am</title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/080522_eveningwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>05/28/08 - 11:36 am</title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/080524_eveningwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>05/28/08 - 11:36 am</title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/080526_afternoonwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>05/28/08 - 11:36 am</title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/080525_eveningwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>05/28/08 - 11:36 am</title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/080526_morningwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>05/28/08 - 11:36 am</title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/080527_eveningwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>05/28/08 - 11:36 am</title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/080523_afternoonwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
</trackList>
</playlist>
It looks like it has obtained the timestamp for the latest file to arrive into the folder, but that timestamp is being replicated for all the entries within that folder.
I appreciate the time that you've taken out to address this query nickName and I hope that the solution is just around the corner, now that I know that it has nothing to do with my server's PHP config.
Tony L
May. 28, 2008nickName
I missed this before. In your code, 2 places, mtime needs to be a single-quoted name, not a variable name.
Change:$items[$entry][$mtime] = exec('stat -c %Y ' . escapeshellarg($entry));to$items[$entry]['mtime'] = exec('stat -c %Y ' . escapeshellarg($entry));and change:$time = date("m/d/y - g:i a", $value[$mtime]);to:$time = date("m/d/y - g:i a", $value['mtime']);
May. 28, 2008Tony L
Getting closer....
Turning mtime from a variable into a single-quoted name produces this script...
<?php
// read through a directory, filter by mp3/jpg/flv and build an XSPF playlist
// set this to a creator name
$creator1 = "Action News 36";
$creator2 = "Webcast";
// search for mp3 and flv files.
$filter1 = 'flv';
// path to the directory you want to scan
// './' = current directory
$directory = "../media/video/webcast/";
// URLs to files
$base_url = 'http://xx.xxx.xxx.xx/';
$files = 'media/video/webcast/';
$images = 'media/images/webcast.png';
// Force Download Script
$fdl_script = 'forcedownload.php?file='; // adjust as necessary, including path information
/////////////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
if(($filter1 == substr(strtolower($entry), strlen($entry) - 3)))
{
$items[$entry]['mtime'] = exec('stat -c %Y ' . escapeshellarg($entry));
}
}
$d->close();
arsort($items);
}
// xml header and opening tags...
header("content-type:text/xml;charset=utf-8");
print <<<END
<?xml version='1.0' encoding='utf-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>Action News 36 Webcast</title>
<trackList>
END;
// loop through the array
foreach($items as $key => $value)
{
$type = substr($key, strlen($key) - 3);
$time = date("m/d/y - g:i a", $value['mtime']);
print <<<END
<track>
<creator>$creator1 $creator2</creator>
<title>$time</title>
<location>$base_url$files$key</location>
<image>$base_url$images</image>
</track>
END;
}
// closing tags
print <<<END
</trackList>
</playlist>
END;
?>
which in turn produces this playlist....
<?xml version='1.0' encoding='utf-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>Action News 36 Webcast</title>
<trackList>
<track>
<creator>Action News 36 Webcast</creator>
<title></title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/080527_afternoonwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title></title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/080528_afternoonwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title></title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/080528_morningwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title></title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/080527_morningwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title></title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/082305_eveningwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title></title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/080526_eveningwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title></title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/080522_eveningwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title></title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/080525_eveningwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title></title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/080526_afternoonwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title></title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/080526_morningwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title></title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/080527_eveningwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title></title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/080524_eveningwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title></title>
<location>http://xx.xxx.xxx.xx/media/video/webcast/080523_afternoonwebcast.flv</location>
<image>http://xx.xxx.xxx.xx/media/images/webcast.png</image>
</track>
</trackList>
</playlist>
The timestamp is now missing from each entry.
Thanks again for all your help - feels like the final stretch of a race.
Tony L
May. 28, 2008nickName
The focus is on this line of code:$items[$entry]['mtime'] = exec('stat -c %Y ' . escapeshellarg($entry));I have to figure out how to accurately simulate that on a Windows system to see what we are missing.
May. 28, 2008Tony L
Okay - drum roll please.....
I've made a modification the above code so that it looks like this:
$items[$entry]['mtime'] = exec('stat -c %Y ' . escapeshellarg("{$directory}/{$entry}"));
When put into the main script....
<?php
// read through a directory, filter by mp3/jpg/flv and build an XSPF playlist
// set this to a creator name
$creator1 = "Action News 36";
$creator2 = "Webcast";
// search for mp3 and flv files.
$filter1 = 'flv';
// path to the directory you want to scan
// './' = current directory
$directory = "../media/video/webcast/";
// URLs to files
$base_url = 'http://xx.xxx.xxx.xx/';
$files = 'media/video/webcast/';
$images = 'media/images/webcast.png';
/////////////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
if(($filter1 == substr(strtolower($entry), strlen($entry) - 3)))
{
$items[$entry]['mtime'] = exec('stat -c %Y ' . escapeshellarg("{$directory}/{$entry}"));
}
}
$d->close();
arsort($items);
}
// xml header and opening tags...
header("content-type:text/xml;charset=utf-8");
print <<<END
<?xml version='1.0' encoding='utf-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>Action News 36 Webcast</title>
<trackList>
END;
// loop through the array
foreach($items as $key => $value)
{
$type = substr($key, strlen($key) - 3);
$time = date("m/d/y - g:i a", $value['mtime']);
print <<<END
<track>
<creator>$creator1 $creator2</creator>
<title>$time</title>
<location>$base_url$files$key</location>
<image>$base_url$images</image>
</track>
END;
}
// closing tags
print <<<END
</trackList>
</playlist>
END;
?>
...it produces the following result....
<?xml version='1.0' encoding='utf-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>Action News 36 Webcast</title>
<trackList>
<track>
<creator>Action News 36 Webcast</creator>
<title>05/28/08 - 6:42 pm</title>
<location>http://98.130.197.37/media/video/webcast/080528_eveningwebcast.flv</location>
<image>http://98.130.197.37/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>05/28/08 - 12:48 pm</title>
<location>http://98.130.197.37/media/video/webcast/080528_afternoonwebcast.flv</location>
<image>http://98.130.197.37/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>05/28/08 - 7:43 am</title>
<location>http://98.130.197.37/media/video/webcast/080528_morningwebcast.flv</location>
<image>http://98.130.197.37/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>05/27/08 - 6:45 pm</title>
<location>http://98.130.197.37/media/video/webcast/080527_eveningwebcast.flv</location>
<image>http://98.130.197.37/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>05/27/08 - 1:45 pm</title>
<location>http://98.130.197.37/media/video/webcast/080527_afternoonwebcast.flv</location>
<image>http://98.130.197.37/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>05/27/08 - 9:02 am</title>
<location>http://98.130.197.37/media/video/webcast/080527_morningwebcast.flv</location>
<image>http://98.130.197.37/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>05/26/08 - 6:52 pm</title>
<location>http://98.130.197.37/media/video/webcast/080526_eveningwebcast.flv</location>
<image>http://98.130.197.37/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>05/26/08 - 12:51 pm</title>
<location>http://98.130.197.37/media/video/webcast/080526_afternoonwebcast.flv</location>
<image>http://98.130.197.37/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>05/26/08 - 7:44 am</title>
<location>http://98.130.197.37/media/video/webcast/080526_morningwebcast.flv</location>
<image>http://98.130.197.37/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>05/25/08 - 7:22 pm</title>
<location>http://98.130.197.37/media/video/webcast/080525_eveningwebcast.flv</location>
<image>http://98.130.197.37/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>05/24/08 - 7:19 pm</title>
<location>http://98.130.197.37/media/video/webcast/080524_eveningwebcast.flv</location>
<image>http://98.130.197.37/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>05/23/08 - 6:44 pm</title>
<location>http://98.130.197.37/media/video/webcast/082305_eveningwebcast.flv</location>
<image>http://98.130.197.37/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>05/23/08 - 12:49 pm</title>
<location>http://98.130.197.37/media/video/webcast/080523_afternoonwebcast.flv</location>
<image>http://98.130.197.37/media/images/webcast.png</image>
</track>
<track>
<creator>Action News 36 Webcast</creator>
<title>05/22/08 - 9:49 pm</title>
<location>http://98.130.197.37/media/video/webcast/080522_eveningwebcast.flv</location>
<image>http://98.130.197.37/media/images/webcast.png</image>
</track>
</trackList>
</playlist>
Once again, thank you nickName for your help on this - could not have done it without you.
Consider this ticket closed.
Tony L
May. 28, 2008nickName
DAMN! Tony, you're no fun at all. This was just about to turn into a full-blown, Sherlock Holmes style sleuthing expedition. And, now you've gone and solved it.
I found a Windows stat.exe and had some code prepared for you to try so we could see what, if anything your stat was returning, so we could progress further.
Well, very good to see that you got it working and this is a good line of code for others to use if they are faced with a similar situation:$items[$entry]['mtime'] = exec('stat -c %Y ' . escapeshellarg("{$directory}/{$entry}"));
Good Luck & Cheers!
May. 29, 2008Tony L
As Lee Corso would say - not so fast my friend! - here's the next task....
You've probably noticed towards the top of the scrip that I separated the <creator> tag into two variables:
// set this to a creator name
$creator1 = "StormTeam 36";
$creator2 = "24-7 Weather";
Here's what I have in mind and I'll work on this some today - based on the info that is now correctly generated to the time variable, I want to have something generated to the <creator> tag that says:
Action News 36 Morning Webcast - when the time is before noon
Action News 36 Afternoon Webcast - when the time is after noon
Action News 36 Evening Webcast - when the time is after 5:00pm and before for 4am
I'll search the 'net for a script that will do the trick for me here, but if you fancy some more sleuthing as it were, have at it.
BTW, the test site is up at http://98.130.197.37/ if you want to have a look at the result of the work done thus far - just select webcast from the dropdown menu above the player.
Look forward to hearing from you,
Tony L
May. 29, 2008nickName
@Tony,
Oh, that's easy. I just need to confirm that you are getting a Unix time stamp of this form "1186535703" from stat.
Then, right after:$time = date("m/d/y - g:i a", $value['mtime']);we digest the time stamp with:$creator_time = date('G', $value['mtime']); to get a number from 0 to 23.
Then:if(($creator_time > 3) && ($creator_time < 13))and
{
$creator = 'Morning';
}
elseif(($creator_time > 12) && ($creator_time < 18))
{
$creator = 'Afternoon';
}
else
{
$creator = 'Evening';
}print <<<ENDUntested, but barring a typO or two, it should work.
<track>
<creator>Action News 36 $creator Webcast</creator>
<title>$time</title>
<location>$base_url$files$key</location>
<image>$base_url$images</image>
</track>
END;
May. 29, 2008Tony L
Back again....
Thanks for that solution - here's what I've come up with based upon that info:
<?php
// read through a directory, filter by mp3/jpg/flv and build an XSPF playlist
// set this to a creator name
$creator1 = "Forecast";
// search for mp3 and flv files.
$filter1 = 'flv';
// path to the directory you want to scan
// './' = current directory
$directory = "../media/video/wx/";
// URLs to files
$base_url = 'http://98.130.197.37/';
$files = 'media/video/wx/';
$images = 'media/images/GENERIC/weather.png';
/////////////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
if(($filter1 == substr(strtolower($entry), strlen($entry) - 3)))
{
$items[$entry]['mtime'] = exec('stat -c %Y ' . escapeshellarg("{$directory}/{$entry}"));
}
}
$d->close();
arsort($items);
}
// xml header and opening tags...
header("content-type:text/xml;charset=utf-8");
print <<<END
<?xml version='1.0' encoding='utf-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>Action News 36 Webcast</title>
<trackList>
END;
// loop through the array
foreach($items as $key => $value)
{
$type = substr($key, strlen($key) - 3);
$time = date("D M Y, h:ia", $value['mtime']);
$numeric = date("H", $value['mtime']);
if($numeric>1&&$numeric<11)
$greeting="Morning";
else if($numeric>11&&$numeric<17)
$greeting="Afternoon";
else
$greeting="Evening";
print <<<END
<track>
<creator>$greeting $creator1</creator>
<title>$time</title>
<location>$base_url$files$key</location>
<image>$base_url$images</image>
</track>
END;
}
// closing tags
print <<<END
</trackList>
</playlist>
END;
?>
....producing this...
<?xml version='1.0' encoding='utf-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>Action News 36 Webcast</title>
<trackList>
<track>
<creator>Morning Webcast</creator>
<title>Thu May 2008, 07:42am</title>
<location>http://98.130.197.37/media/video/webcast/080529_morningwebcast.flv</location>
<image>http://98.130.197.37/media/images/GENERIC/webcast.png</image>
</track>
<track>
<creator>Evening Webcast</creator>
<title>Wed May 2008, 06:42pm</title>
<location>http://98.130.197.37/media/video/webcast/080528_eveningwebcast.flv</location>
<image>http://98.130.197.37/media/images/GENERIC/webcast.png</image>
</track>
<track>
<creator>Afternoon Webcast</creator>
<title>Wed May 2008, 12:48pm</title>
<location>http://98.130.197.37/media/video/webcast/080528_afternoonwebcast.flv</location>
<image>http://98.130.197.37/media/images/GENERIC/webcast.png</image>
</track>
<track>
<creator>Morning Webcast</creator>
<title>Wed May 2008, 07:43am</title>
<location>http://98.130.197.37/media/video/webcast/080528_morningwebcast.flv</location>
<image>http://98.130.197.37/media/images/GENERIC/webcast.png</image>
</track>
<track>
<creator>Evening Webcast</creator>
<title>Tue May 2008, 06:45pm</title>
<location>http://98.130.197.37/media/video/webcast/080527_eveningwebcast.flv</location>
<image>http://98.130.197.37/media/images/GENERIC/webcast.png</image>
</track>
<track>
<creator>Afternoon Webcast</creator>
<title>Tue May 2008, 01:45pm</title>
<location>http://98.130.197.37/media/video/webcast/080527_afternoonwebcast.flv</location>
<image>http://98.130.197.37/media/images/GENERIC/webcast.png</image>
</track>
<track>
<creator>Morning Webcast</creator>
<title>Tue May 2008, 09:02am</title>
<location>http://98.130.197.37/media/video/webcast/080527_morningwebcast.flv</location>
<image>http://98.130.197.37/media/images/GENERIC/webcast.png</image>
</track>
<track>
<creator>Evening Webcast</creator>
<title>Mon May 2008, 06:52pm</title>
<location>http://98.130.197.37/media/video/webcast/080526_eveningwebcast.flv</location>
<image>http://98.130.197.37/media/images/GENERIC/webcast.png</image>
</track>
<track>
<creator>Afternoon Webcast</creator>
<title>Mon May 2008, 12:51pm</title>
<location>http://98.130.197.37/media/video/webcast/080526_afternoonwebcast.flv</location>
<image>http://98.130.197.37/media/images/GENERIC/webcast.png</image>
</track>
<track>
<creator>Morning Webcast</creator>
<title>Mon May 2008, 07:44am</title>
<location>http://98.130.197.37/media/video/webcast/080526_morningwebcast.flv</location>
<image>http://98.130.197.37/media/images/GENERIC/webcast.png</image>
</track>
<track>
<creator>Evening Webcast</creator>
<title>Sun May 2008, 07:22pm</title>
<location>http://98.130.197.37/media/video/webcast/080525_eveningwebcast.flv</location>
<image>http://98.130.197.37/media/images/GENERIC/webcast.png</image>
</track>
<track>
<creator>Evening Webcast</creator>
<title>Sat May 2008, 07:19pm</title>
<location>http://98.130.197.37/media/video/webcast/080524_eveningwebcast.flv</location>
<image>http://98.130.197.37/media/images/GENERIC/webcast.png</image>
</track>
<track>
<creator>Evening Webcast</creator>
<title>Fri May 2008, 06:44pm</title>
<location>http://98.130.197.37/media/video/webcast/082305_eveningwebcast.flv</location>
<image>http://98.130.197.37/media/images/GENERIC/webcast.png</image>
</track>
<track>
<creator>Afternoon Webcast</creator>
<title>Fri May 2008, 12:49pm</title>
<location>http://98.130.197.37/media/video/webcast/080523_afternoonwebcast.flv</location>
<image>http://98.130.197.37/media/images/GENERIC/webcast.png</image>
</track>
<track>
<creator>Evening Webcast</creator>
<title>Thu May 2008, 09:49pm</title>
<location>http://98.130.197.37/media/video/webcast/080522_eveningwebcast.flv</location>
<image>http://98.130.197.37/media/images/GENERIC/webcast.png</image>
</track>
</trackList>
</playlist>
Thanks again for your help nickName.
Tony L
May. 29, 2008nickName
I would prefer to use date('G', $value['mtime']); to get 24-hour time without the leading zero, but I guess it doesn't matter.
May. 30, 2008acc
hello am testing this but doesent work, please heeeeeeelp!
<embed
src="http://www.luisoliva.org/imagerotator/imagerotator.swf"
width="160"
height="155"
allowscriptaccess="always"
allowfullscreen="true"
flashvars="height=155&width=160&file=<?php
/*
* This is a sample file that reads through a directory, filters the mp3/jpg/flv
* files and builds a playlist from it. After looking through this file, you'll
* probably 'get the idea' and'll be able to setup your own directory.
*
*/
// set this to a creator name
$creator = "Administrador";
// search for mp3 files. set this to '.flv' or '.jpg' for the other scripts
$filter = ".JPG";
// path to the directory you want to scan
// "./" = current directory
$directory = "./imagerotator/n_producciones/";
// URL to files
$url = "http://www.luisoliva.org";
/////////////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false))
{
$items[$entry]['mtime'] = filemtime($entry);
}
}
$d->close();
arsort($items);
}
// the playlist is built in an xspf format
// first, we'll add an xml header and the opening tags...
header("content-type:text/xml;charset=utf-8");
echo "<?xml version='1.0' encoding='utf-8'?>\n";
echo "<playlist version='1' xmlns='http://xspf.org/ns/0/'>\n";
echo " <title>Sample PHP Generated Playlist</title>\n";
echo " <info>" . $url . "</info>\n";
echo " <trackList>\n";
// ...then we loop through the array...
foreach($items as $key => $value)
{
$title = substr($key, 0, strlen($key) - 4);
echo " <track>\n";
echo " <title>" . $title . "</title>\n";
echo " <creator>" . $creator . "</creator>\n";
echo " <info>" . $url . "</info>\n";
echo " <location>" . $url . '/' . $key . "</location>\n";
echo " </track>\n";
}
// ...and last we add the closing tags
echo " </trackList>\n";
echo "</playlist>\n";
/*
* That's it! You can feed this playlist to the SWF by setting this as it's 'file'
* parameter in your HTML page.
*/
?>&format=rss_200&overstretch=true"
/>
May. 30, 2008Farooq
Hi there,
I downloaded this module to use it in Joomla, but it doesn't work. Will pls anybody tell me what i did wrong?
I really dont know where in joomla i have to paste the folderlist and playlist.
www.mysite.com
www.mysite.com/audio audio directory location
www.mysite.com/modules/mod_flashmp3player/ joomla modulelocation
In the last bookmark you'll see the playlist and the folderlist and mp3player.swf
PLEASE HELP ME TO CONFIGURE THE AUTOMATIC PLAYLIST!
May. 30, 2008Tony L
@acc
Why not create a separate .php file and have the embed code for the MediaPlayer draw the data from there to the file variable - i've tried what you are attempting and this solution is a whole lot less painful.
Tony L
May. 30, 2008Tony L
@Farooq
You'll need to go into a little bit more detail with your query.
I assume that you're trying to use the All Video Plugin from the joomlaworks.gr site - until that plugin is updated to accommodate the use of the external file variable, you'll be better off embeding the code that you can obtain from the Setup Wizard (http://www.jeroenwijering.com/?page=wizard) into a newly-created Custom HTML module in Joomla. Don't forget to put the mediaplayer.swf and swfobject.js files that you can download from the site into the root folder of your website.
From there, it's pretty straightforward. You create a .php file with the auto generated playlist script that's been contributed above and with a few adjustments to the code to so that it can find the .flv files in a folder, you should be on your way.
Tony L
May. 30, 2008Tony L
@nickName,
I have another hypothetical scenario....
Say that you just want the above script to generate a single-entry playlist based on the most recent file to be uploaded to that folder - what change would need to be made to the script to make that happen?
I'm think probably that a loop needs to be taken out, but I'm not entirely sure where from on the script.
Any help that you maybe able to render would be most appreciated again.
Tony L
May. 30, 2008Farooq
Thanks for your reaction, but i want to use XML playlist because I have such a lot of numbers.
May. 30, 2008Tony L
@Farooq,
I don't know if you're confused in some way but that .php file generates an output that is XML format and one that the player will read. So far the PHP method is the only one I have found that would perform this kind of function. And if you have that many files to content with, I certainly wouldn't want to code the file in by hand just for the sake of a .xml extension.
Tony L
May. 30, 2008nickName
The array is already sorted by mtime, latest first, so just use the first array element.$time = date('D M Y, h:ia', $items[key($items)]['mtime']);Not tested... I'm not sure that you need the squirrelie-curlie brackets around key($items), but it can't hurt.
$numeric = date('G', $items[key($items)]['mtime']);
if(($numeric > 1) && ($numeric < 11))
{
$greeting = 'Morning';
}
elseif(($numeric > 11) && ($numeric < 17))
{
$greeting = 'Afternoon';
}
else
{
$greeting = 'Evening';
}
print <<<END
<?xml version='1.0' encoding='utf-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>Action News 36 Webcast</title>
<trackList>
<track>
<creator>$greeting $creator1</creator>
<title>$time</title>
<location>$base_url$files{key($items)}</location>
<image>$base_url$images</image>
</track>
</trackList>
</playlist>
END;
?>
Jun. 02, 2008Tony L
@ nickName
Thanks for that response - however the result of that modification was this:
<?xml version='1.0' encoding='utf-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>Action News 36 Webcast</title>
<trackList>
<track>
<creator>Afternoon Webcast</creator>
<title>Mon Jun 2008, 12:54pm</title>
<location>http://98.130.197.37/media/video/webcast/{key(Array)}</location>
<image>http://98.130.197.37/media/images/GENERIC/webcast.png</image>
</track>
</trackList>
</playlist>
Any help you can render again would be most appreciated.
Tony L
Jun. 02, 2008nickName
According to the manual, this should work, but it doesn't:{${key($items)}}So do it this way:$time = date('D M Y, h:ia', $items[key($items)]['mtime']);and:
$numeric = date('G', $items[key($items)]['mtime']);
$item = key($items);<location>$base_url$files$item</location>
Jun. 03, 2008Tony L
Thank you - that works great now.
Tony L
Jun. 08, 2008Beejay
Ciao,
maybe this is not the right thread to post this, but my issue is related to it.
i need a playlist generator for flv and mp3 files and i try a lot of .php's posted on this forum...but the only one working is the one posted above by Tony L .
My problem is the lastdate displaying instead of the filename in the JW player playlist...
how can i modify the script to display the filenames?
here it is
<?php
// read through a directory, filter by mp3/jpg/flv and build an XSPF playlist
// set this to a creator name
$creator1 = "myname";
// search for mp3 and flv files.
$filter1 = 'mp3';
$filter2 = 'flv';
// path to the directory you want to scan
// './' = current directory
$directory = "./";
// URLs to files
$base_url = 'http://www.xxxx.it/';
$files = 'media/';
$images = 'media/images/logoweb.png';
// Force Download Script
$fdl_script = 'forcedownload.php?file='; // adjust as necessary, including path information
/////////////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps1 = strpos(strtolower($entry), $filter1);
$ps2 = strpos(strtolower($entry), $filter2);
if (!(($ps1 === false) && ($ps2 === false)))
{
$items[$entry]['mtime'] = filemtime($entry);
}
}
$d->close();
arsort($items);
}
// xml header and opening tags...
header("content-type:text/xml;charset=utf-8");
print <<<END
<?xml version='1.0' encoding='utf-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>Action News 36 Webcast</title>
<trackList>
END;
// loop through the array
foreach($items as $key => $value)
{
$type = substr($key, strlen($key) - 3);
$time = date("m/d/y - g:i a", $value['mtime']);
print " <track>\n";
{
print " <creator>" . $creator1 . " " . $creator2 ."</creator>\n";
}
print <<<END
<title>$time</title>
<location>$base_url$files$key</location>
<image>$base_url$images</image>
</track>
END;
}
// closing tags
print <<<END
</trackList>
</playlist>
END;
?>
i'm a total newbie, i try different playlist generators, but this is the only one running perfectly, all the other php scripts don't work, also trying to change path locations, etc...
Only this works...but i dont know how to change in the code. any idea?
thanks for any help.
PS: these scripts are really powerful. Great Job everybody!
Jun. 12, 2008fera
Hi all.
i've a joomla 1.5.3 website which use all video reloaded module ( http://allvideos.fritz-elfert.de/ ). this module use your fantastic video player.
i'm using a php file which autogenerate the xml playlist.
example: i have a folder with file 1.flv, 2.flv, 10.flv files in it.
the result of the php file is a xml like this:
track 1 -> 1.flv
track 2 -> 2.flv
track 3 -> 10.flv
(order a-z of the folder)
my question is: how to obtain the inverse order??
i would like have an output like this:
track 1 -> 10.flv
track 2 -> 2.flv
track 1 -> 1.flv
(order z-a of the folder)
Please help me :'''-(
Jun. 12, 2008fera
example:
original playlist:
<playlist version="1" xmlns="http://xspf.orig/ns/0/">
<title>CG Playlist</title>
<trackList>
<track>
<title>Reloaded</title>
<location>/images/stories/videos/matrix.flv</location>
<image>/images/stories/videos/matrix_thumb_small.jpg</image>
</track>
</trackList>
</playlist>
autogenerate playlist from a folder with files order -> a-z
<?php
define('DS', DIRECTORY_SEPARATOR);
$folder = (isset($_REQUEST['folder'])) ? $_REQUEST['folder'] : "";
$thumbfolder = ($folder) ? $folder."/" : "";
function files($path, $filter = '.', $recurse = false, $fullpath = false, $exclude = array('.svn', 'CVS', 'php'), $include = array('flv','mp4','swf','3gp','mp3','rbs'))
{
// Initialize variables
$arr = array ();
// Is the path a folder?
if (!is_dir($path)) {
?>
<script language="javascript" type="text/javascript">alert('Path is not a folder <?php echo $path; ?>'); </script>
<?php
return false;
}
// read the source directory
$handle = opendir($path);
while (($file = readdir($handle)) !== false)
{
$dir = $path.DS.$file;
$isDir = is_dir($dir);
if (($file != '.') && ($file != '..') && (!in_array($file, $exclude))) {
if ($isDir) {
if ($recurse) {
if (is_integer($recurse)) {
$recurse--;
}
$arr2 = files($dir, $filter, $recurse, $fullpath);
$arr = array_merge($arr, $arr2);
}
} else {
if (preg_match("/$filter/", $file)) {
$path_parts = pathinfo($path.DS.$file);
if(in_array($path_parts['extension'], $include)){
if ($fullpath) {
$arr[] = $path.DS.$file;
} else {
$arr[] = $file;
}
}
}
}
}
}
//closedir($handle);
//asort($arr);
return $arr;
}
$path = dirname(__FILE__);
$files = files($path.DS.$folder);
$url = dirname($_SERVER['REQUEST_URI']);
?>
<playlist version="1" xmlns="http://xspf.org/ns/0/">
<title>CG Playlist</title>
<trackList>
<?php
foreach($files as $f){
if(file_exists($path.DS.$folder.DS."thumbnail".DS.$f.".jpg")){
$img = "$url/{$thumbfolder}thumbnail/$f.jpg";
}elseif(file_exists($path.DS.$folder.DS."thumbnail".DS.$f.".gif")){
$img = "$url/{$thumbfolder}thumbnail/$f.gif";
} else $img = "";
?>
<track>
<title><?php echo $f; ?></title>
<location><?php echo "$url/$folder/$f";?></location>
<image><?php echo $img; ?></image>
</track>
<?php
}
?>
</trackList>
</playlist>
Jun. 12, 2008fera
i've resolt including un rsort();
Aug. 07, 2008Earl
Hello and MANY THANKS for the script - I'm totally new to php.
My imports have spaces in the filenames - I'm not sure this is compatible with any browser, so here's what I added to the main loop at the bottom:
$loc = str_replace(" ", "%20", $key);
and then replaced:
echo " <location>" . $url . '/' . $key . "</location>\n";
with:
echo " <location>" . $url . '/' . $loc . "</location>\n";
If I'm smoking something on this "any browser" thing, please let me know.
Also, if this helps other newbies out there, I create my mp3s using iTunes, that by default, adds a track number to the song title. If one uses the very excellent player from http://www.boutell.com/xspf you're stuck with numbers from the player and numbers from the songs. You can turn off track numbering on iTunes, but that's a pain if you want to go back and forth with track numbering.
Instead, I changed this:
$title = substr($key, 0, strlen($key) - 4);
to this:
$title = substr($key, 3, strlen($key) - 7);
I use Apache under OS X Leopard, as it's the easiest for me to run the php there. If anyone's having trouble there, then this will help to fix it: http://discussions.apple.com/thread.jspa?threadID=1195856&tstart=0
Thanks for the bandwidth for this poast!
Aug. 09, 2008Some Dude
Just wanted to say thank you so much for this...
I was able to modify this to do perfectly what I needed, which was to generate a shuffled, but TRUNCATED, version of a photo playlist for a photo slideshow embed. Basically, I wanted to be able to drop in hundreds, or even thousands, of photos into a directory, and then autogenerate a shuffled playlist of only maybe 30 photos each. Essentially, it's generating random 30-picture slideshows now from a pool of 600+ photos which I can add or subtract to anytime. This helps on the bandwidth front, as I have a slideshow that constantly runs on some of my pages, but still lets me get hundreds/thousands of photos into the mix on each refresh of the playlist.php file.
The hack basically starts by getting the original script to run, and then changing the sort to shuffle (using more code I found here, thanks!) and the "for each loop" to a "for next loop" limited by the number of photos you want to end up in the autogenerated playlist. For me personally, I also had to mod the mtime section to get that to work on my server originally, even though I'm not really using that data now, and I modded the xml output for my needs -- your needs may be different, so head's up. And remember, this was geared towards a photo slideshow, but I'm sure could be further tweaked to work for other media.
So, here's my code for those who might be interested:
<?php
$playlistmax = 25;
$filter = ".jpg";
$directoryscanned = "/home/public_html/scanneddirectory";
$urlinplaylist = "/scanneddirectory";
$linkbackhome = "http://www.yoursite.com/";
@$d = dir($directoryscanned);
if ($d)
{
while($entry = $d->read())
{
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false))
{
// $items[$entry]['mtime'] = filemtime($entry);
$mtime = exec ('stat -c %Y '. escapeshellarg ($path));
$items[$entry]['mtime'] = $mtime;
}
}
$d->close();
// arsort($items);
shuffle_assoc($items);
}
header("content-type:text/xml;charset=utf-8");
echo "<?xml version='1.0' encoding='utf-8'?>\n";
echo "<playlist version='1' xmlns='http://xspf.org/ns/0/'>\n";
echo " <trackList>\n";
$AllKeys = array_keys($items);
for ($i = 0; $i < min($playlistmax, count($items) - 1); $i++)
{
echo " <track>\n";
echo " <location>" . $urlinplaylist . '/' . $AllKeys[$i] . "</location>\n";
echo " <info>$linkbackhome</info>\n";
echo " </track>\n";
}
echo " </trackList>\n";
echo "</playlist>\n";
function shuffle_assoc(&$array)
{
if (count($array)>1)
{
$keys = array_rand($array, count($array));
foreach($keys as $key)
{
$new[$key] = $array[$key];
$array = $new;
}
return true;
}
}
?>
Aug. 20, 2008wallwriter
I've spent all day trying to get this thign to work and i'm having no luck.
As it stands, the player loads on the page with the tracklist showing below, all the songs are there, but when i go to play them, i get error #2032.
Can anyone help.
the code in the html page is as follows:
<script type='text/javascript' src='swfobjectvid.js'></script>
<script type='text/javascript'>
var s1 = new SWFObject('playervid.swf','player','400','300','9');
s1.addParam('allowfullscreen','true');
s1.addParam('allowscriptaccess','always');
s1.addParam('flashvars','&file=playlist.php&playlist=bottom');
s1.write('preview');
</script>
Is there sth wrong here?
(If need be I can post the playlist.php code aswell)
The playlist.php is in the same folder as the play bt the mp3's are in another folder namely: Music/Album Name/
As i say the php seems to list them ok, even the play lists them in the playlist viewer, it's just this error when i go to play them.
thanks in advance for any help.
Aug. 20, 2008kLink
More useful would be the output of the playlist.php script (the actual playlist file).
Do the location elements contain a valid path to your MP3 file?
Either a full URI like this: http://my.domain.com/Music/Album Name/song1.mp3
Or an absolute path like this: /Music/Album Name/song1.mp3
Or a relative path from the location of the HTML document containing the player embedding code, like this: Music/Album Name/song1.mp3
Aug. 20, 2008wallwriter
Here is the playlist file. The it is located in the same folder as the mp3 files.
<?php
/*
* This is a sample file that reads through a directory, filters the mp3/jpg/flv
* files and builds a playlist from it. After looking through this file, you'll
* probably 'get the idea' and'll be able to setup your own directory.
*
*/
// set this to a creator name
$creator = "Gafyn Davies";
// search for mp3 files. set this to '.flv' or '.jpg' for the other scripts
$filter = ".mp3";
// path to the directory you want to scan
// "./" = current directory
$directory = "./";
// URL to files
$url = "http://www.gafyndavies.com/music.html";
/////////////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false))
{
$items[$entry]['mtime'] = filemtime($entry);
}
}
$d->close();
arsort($items);
}
// the playlist is built in an xspf format
// first, we'll add an xml header and the opening tags...
header("content-type:text/xml;charset=utf-8");
echo "<?xml version='1.0' encoding='utf-8'?>\n";
echo "<playlist version='1' xmlns='http://xspf.org/ns/0/'>\n";
echo " <title>Sample PHP Generated Playlist</title>\n";
echo " <info>" . $url . "</info>\n";
echo " <trackList>\n";
// ...then we loop through the array...
foreach($items as $key => $value)
{
$title = substr($key, 0, strlen($key) - 4);
echo " <track>\n";
echo " <creator>" . $creator . "</creator>\n";
echo " <title>" . $title . "</title>\n";
echo " <location>" . $url . '/' . $key . "</location>\n";
echo " <info>" . $url . "</info>\n";
echo " </track>\n";
}
// ...and last we add the closing tags
echo " </trackList>\n";
echo "</playlist>\n";
/*
* That's it! You can feed this playlist to the SWF by setting this as it's 'file'
* parameter in your HTML page.
*/
?>
Aug. 20, 2008kLink
This:// URL to filesis wrong, it should only be the URL to the directory containing the media files because the filenames get added to it:
$url = "http://www.gafyndavies.com/music.html";echo " <location>" . $url . '/' . $key . "</location>\n";to make a full URI.
Probably should be:$url = "http://www.gafyndavies.com/Music/Album Name";then the full URI to the MP3 file would be:http://www.gafyndavies.com/Music/Album Name/Some Song.mp3
Aug. 21, 2008wallwriter
thanks, it looks like it's working now.
Aug. 21, 2008wallwriter
To change this php file to create a playlist of video (flv) or pics (jpg), am i correct in thinking that i only need to change the filter from mp3 >> flv or >>jpg respectively? or is there something else i need to look at?
Aug. 21, 2008kLink
@wallwriter,
Correct, just change the filter for jpg, mp3, or mp4.
Aug. 24, 2008Imran
Heres my code:
<?php
/*
* This is a sample file that reads through a directory, filters the mp3/jpg/flv
* files and builds a playlist from it. After looking through this file, you'll
* probably 'get the idea' and'll be able to setup your own directory.
*
*/
// search for mp3 files. set this to '.flv' or '.jpg' for the other scripts
$filter = ".mp3";
// path to the directory you want to scan
// "./" = current directory
$directory = "./";
// URL to files
$url = "http://myfilelocation.com";
/////////////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false))
{
$items[$entry]['mtime'] = exec ('stat -c %Y '. escapeshellarg ($entry));
}
}
$d->close();
arsort($items);
}
// the playlist is built in an xspf format
// first, we'll add an xml header and the opening tags
echo "<?xml version='1.0' encoding='utf-8'?>\n";
echo "<playlist version='1' xmlns='http://xspf.org/ns/0/'>\n";
echo " <title>Music Player - Playlist</title>\n";
echo " <info>" . $url . "</info>\n";
echo " <trackList>\n";
// ...then we loop through the array...
foreach($items as $key => $value)
{
$title = substr($key, 0, strlen($key) - 10);
echo " <track>\n";
echo " <title>" . $title . "</title>\n";
echo " <location>" . $url . '/' . $key . "</location>\n";
echo " </track>\n";
}
// ...and last we add the closing tags
echo " </trackList>\n";
echo "</playlist>\n";
/*
* That's it! You can feed this playlist to the SWF by setting this as it's 'file'
* parameter in your HTML page.
*/
?>
Im having a problem though, i changed hosts where the music files are hosted (i moved the script the to same host)
But for some reason its not ordering them right. It should be from Latest to Oldest but its just randomly generating one. Its not random playlist everytime, its they all are in the same position on reload. But I dont understand why it isnt doing it by uploaded latest to oldest now :-S
Aug. 24, 2008kLink
This line of code:$items[$entry]['mtime'] = exec ('stat -c %Y '. escapeshellarg ($entry)); gets the file mtime (last modified time) so the files can be sorted by time.
This particular code was written for servers running on the Linux operating systems. Since you have changed hosts, the underlying operating system may have changed. If possible, find out what operating system your host is running.
The equivalent code using the PHP filemtime() function is:$items[$entry]['mtime'] = filemtime($directory . "/" . $entry);You might try this code.
further references: http://www.php.net/function.filemtime
Aug. 24, 2008Imran
Thanks the filemtime php code fixed the problem :-)
Aug. 24, 2008kLink
@Imran,
You're welcome.
I'm pleasantly surprised that it was so easy.
Aug. 25, 2008Satish Yagnik
hi
i m using JW image rotator in Dotnetnuke for showing topstories ... i have 2 questions
1. it is posible to change the look & feel of the controller & title font size.... measn i want to show the title with bigger & it should not go while mouse rollout ...
2. it is possible to autogenrate XML file using ASP.net like u are using PHP
Thanks
Oct. 23, 2008TP
Thanks so much for posting the info. I got it working!!
TP
Oct. 27, 2008Ricardo
Is possible to scan a local directory (D:/videos), from this script running in the website server. ?
I mean something like this:
// path to the directory you want to scan
$directory = "file:///d:/videos/";
I've tried as above but nothing happens, the playlist is not generated (only header lines).
Oct. 28, 2008kLink
Generally speaking, online resources don't have access to local files.
Nov. 05, 2008KP
Hi:
I'm using the JW Player in CMSMS. the site i'm working on is <http://obadiahlyrics.com/audio.php>. the files player.swf, the obiwoodPlaylist.php, the player.swf, and the mp3 file are all in the same folder.
the playlist code is the same as the one your posted at the top of this page, AJAX, except for:
// set this to a creator name
$creator = "Obi Wood";
// search for mp3 files. set this to '.flv' or '.jpg' for the other scripts
$filter = ".mp3";
// path to the directory you want to scan
// "./" = current directory
$directory = "./";
// URL to files
$url = "http://obadiahlyrics.com/uploads/audio";
if you navigate to the url i posted, you'll see the player says; 0: Error #2032
I have no clue where to begin. It's worth noting, that the server is linux running php as cgi.
suggestions?
Nov. 06, 2008keyman
Hello !
I can't get your script working...
sorry i'm a newbie in PHP, but it is very strange, because it work (I'm getting a good XML playlist) but only at the end of file...
So anyway, I need a script simplier than this one,
Just : Looking into a folder, list all the .jpg files in this folder
and make a xml file with this listing...(to use has playlist with jpg-rotator...)
can anyone help ?!
Thank you very much in advance !
Cheers
keyman
Nov. 07, 2008kLink
@KP,
I get a "404 File Not found" error when I try to access your playlist at:
http://obadiahlyrics.com/obiwoodPlaylist.php
Nov. 10, 2008keyman
humm;
it is not my playlist...
anyway...
I got it, with the "VBS" script running on windows...
but it is not a real solutions...
what about if I want to creat playlists online on the fly when a new media (image/sound/video) are uploaded into a specific folder ?
Thanks if you got a solution for me...
anyway thanks for your time kLink !
Nov. 12, 2008KP
Hi kLink:
The file obiwoodPlaylist.php is actually residing in the uploads/audio/ directory. The reasoning for this is that the client needs to be able to upload his audio to the folder directly.
i'm getting close to launching, would really like to have this solved. Would you mind taking a look again? Also, I want to remove the URL link, it's not required. Here's the content of the file:
<?php
/*
* This is a sample file that reads through a directory, filters the mp3/jpg/flv
* files and builds a playlist from it. After looking through this file, you'll
* probably 'get the idea' and'll be able to setup your own directory.
*
*/
// set this to a creator name
$creator = "Obi Wood";
// search for mp3 files. set this to '.flv' or '.jpg' for the other scripts
$filter = ".mp3";
// path to the directory you want to scan
// "./" = current directory
$directory = "./";
// URL to files
$url = "http://obadiahlyrics.com/uploads/audio";
/////////////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false))
{
$items[$entry]['mtime'] = filemtime($entry);
}
}
$d->close();
arsort($items);
}
// the playlist is built in an xspf format
// first, we'll add an xml header and the opening tags...
header("content-type:text/xml;charset=utf-8");
echo "<?xml version='1.0' encoding='utf-8'?>\n";
echo "<playlist version='1' xmlns='http://xspf.org/ns/0/'>\n";
echo " <title>Obadiah Lyrics - Sample Audio</title>\n";
// echo " <info>" . $url . "</info>\n";
echo " <trackList>\n";
// ...then we loop through the array...
foreach($items as $key => $value)
{
$title = substr($key, 0, strlen($key) - 4);
echo " <track>\n";
echo " <creator>" . $creator . "</creator>\n";
echo " <title>" . $title . "</title>\n";
// echo " <location>" . $url . '/' . $key . "</location>\n";
// echo " <info>" . $url . "</info>\n";
echo " </track>\n";
}
// ...and last we add the closing tags
echo " </trackList>\n";
echo "</playlist>\n";
/*
* That's it! You can feed this playlist to the SWF by setting this as it's 'file'
* parameter in your HTML page.
*/
?>
Thank you.
Nov. 12, 2008kLink
@KP,
Do you need your files sorted, latest first?
The script does that sorting, but it has the Windows code. I have the Linux code if you need to do the sorting, or we can just remove that altogether.
Nov. 14, 2008KP
Hi kLink:
Sorry about the late reply. It's been crazy busy.
I would love to sort by category or alphabetically. The more options the clients has the better. He's a retired fellow with limited knowledge. However, the first step is to have it working, then we can add the glitz.
Is there a way we can communicate via IM or email? I'm on Skype (femtechmedia) or AIM (newagekat) Let me know and I'll activate non-buddy contacts.
I'll check this page on and off all day. Thank you.
Nov. 14, 2008kLink
Here's sorting alphabetically by filename normal order (a-z).
<?php
// set this to a creator name
$creator = "Obi Wood";
// search for mp3 files
$filter = ".mp3";
// path to the directory you want to scan
// "./" = current directory
$directory = "./";
// URL to files
$url = "http://obadiahlyrics.com/uploads/audio";
/////////////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false))
{
//////////////////////////////////////////// Windows debug code \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// unset($output);
// exec('stat -t ' . escapeshellarg($entry), $output);
// print "<pre>";
// print_r($output);
// exit;
// $output = explode(' ', $output[0]);
// $items[$entry]['mtime'] = $output[10];
//////////////////////////////////////////// Windows debug code \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//...Windows normal code - sorting by mtime
// $items[$entry]['mtime'] = filemtime($entry);
//...Linux/Unix code - sorting by mtime
// There is an option in the "stat" command to return the MAC timestamps of a file in epoch time,
// where Access/Modify/Change are given in format %X/%Y/%Z.
// $items[$entry]['mtime'] = exec('stat -c %Y ' . escapeshellarg("{$directory}/{$entry}"));
//...Windows/Linux/Unix normal code - sorting by filename
$items[$entry] = $entry;
}
}
$d->close();
// reverse sort - latest first
// arsort($items);
// normal sort - alphabetically by filename
asort($items);
}
// xml header and opening tags
header("content-type:text/xml;charset=utf-8");
print <<<END
<?xml version='1.0' encoding='utf-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>Obadiah Lyrics - Sample Audio</title>
<trackList>
END;
// loop through the array to build the track
foreach($items as $key => $value)
{
$title = substr($key, 0, strlen($key) - 4);
print <<<END
<track>
<creator>$creator</creator>
<title>$title</title>
<location>$url/$key</location>
</track>
END;
}
// closing tags
print <<<END
</trackList>
</playlist>
END;
?>
Typical output:
<?xml version='1.0' encoding='utf-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>Obadiah Lyrics - Sample Audio</title>
<trackList>
<track>
<creator>Obi Wood</creator>
<title>song1</title>
<location>http://obadiahlyrics.com/uploads/audio/song1.mp3</location>
</track>
<track>
<creator>Obi Wood</creator>
<title>song10</title>
<location>http://obadiahlyrics.com/uploads/audio/song10.mp3</location>
</track>
<track>
<creator>Obi Wood</creator>
<title>song11</title>
<location>http://obadiahlyrics.com/uploads/audio/song11.mp3</location>
</track>
<track>
<creator>Obi Wood</creator>
<title>song12</title>
<location>http://obadiahlyrics.com/uploads/audio/song12.mp3</location>
</track>
<track>
<creator>Obi Wood</creator>
<title>song2</title>
<location>http://obadiahlyrics.com/uploads/audio/song2.mp3</location>
</track>
<track>
<creator>Obi Wood</creator>
<title>song3</title>
<location>http://obadiahlyrics.com/uploads/audio/song3.mp3</location>
</track>
<track>
<creator>Obi Wood</creator>
<title>song4</title>
<location>http://obadiahlyrics.com/uploads/audio/song4.mp3</location>
</track>
<track>
<creator>Obi Wood</creator>
<title>song5</title>
<location>http://obadiahlyrics.com/uploads/audio/song5.mp3</location>
</track>
<track>
<creator>Obi Wood</creator>
<title>song6</title>
<location>http://obadiahlyrics.com/uploads/audio/song6.mp3</location>
</track>
<track>
<creator>Obi Wood</creator>
<title>song7</title>
<location>http://obadiahlyrics.com/uploads/audio/song7.mp3</location>
</track>
<track>
<creator>Obi Wood</creator>
<title>song8</title>
<location>http://obadiahlyrics.com/uploads/audio/song8.mp3</location>
</track>
<track>
<creator>Obi Wood</creator>
<title>song9</title>
<location>http://obadiahlyrics.com/uploads/audio/song9.mp3</location>
</track>
</trackList>
</playlist>
Sorry, I don't do those messenger things. email only by PayPal.
Nov. 19, 2008KP
Hello kLink:
I am still having the same error message. 0: Error @2032
I'm using jw player v4.16 Here's what I have done:
In /uploads/audio/ i have placed the following:
player.swf
swfobject.js
obiwoodPlaylist.php - using your sorted coded for Linux.
I will survive.mp3 - for testing only
I have placed the call to swfobject.js in the head
I have added this code to the audio page:
<script type="text/javascript">
var s1 = new SWFObject('uploads/audio/player.swf','mp3','320','256','9');
s1.addParam("allowscriptaccess","always");
s1.addParam('allowfullscreen','false');
s1. addParam('flashvars','&author=Obidiah Lyrics&description=Sample audio only&file=obiwoodPlaylist.php&plugins=tipjar-1&tipjar.title=Please Donate&tipjar.text=If you like the audio, lyrics, and sonnets on this site, please help support the website by making a small donation&tipjar.business=obiwood@obiwood@obadiahlyrics.com&tipjar.show_pause=true&tipjar.currency_code=CAD&tipjar.return_url=http://obadiahlyrics.com/thank-you.php&backcolor=4E6D82&screencolor=4E6D82&frontcolor=ffffff&lightcolor=9FCEE8&type=sound&playlist=bottom&playlistsize=180&logo=uploads/images/logo.png');
s1.write('audioPlayer');
</script>
The plugin was added today, but the error has been the same since day one. what am I missing? Please help, i'm going loony fast.
Thank you.
Nov. 19, 2008kLink
These are the results from testing your URIs:You need to correct the server errors on the last two files, then test these URIs again.
http://www.obadiahlyrics.com/audio.php ----------------------- OK
http://obadiahlyrics.com/uploads/audio/player.swf ------------ OK
http://obadiahlyrics.com/uploads/audio/swfobject.js ---------- OK
http://obadiahlyrics.com/uploads/audio/obiwoodPlaylist.php --- "403: Forbidden"
http://obadiahlyrics.com/uploads/audio/I will survive.mp3 ---- "404: Not found"
As soon as you start using a playlist, all of the File Properties:
[{( Reference: http://code.jeroenwijering.com/trac/wiki/FlashVars#Fileproperties )}]
MUST come from the equivalent playlist elements:
[{( Reference: http://code.jeroenwijering.com/trac/wiki/FlashFormats#Playlistformats )}].
You might want to check your 'tipjar.business' email address.
<script type="text/javascript">
var s1 = new SWFObject('uploads/audio/player.swf', 'mp3', '320', '256', '9.0.124');
s1.addParam('allowscriptaccess', 'always');
s1.addParam('allowfullscreen', 'false');
s1. addVariable('author', 'Obidiah Lyrics');
s1. addVariable('description', 'Sample audio only');
s1. addVariable('file', 'obiwoodPlaylist.php);
s1. addVariable('type', 'sound');
s1. addVariable('plugins', 'tipjar-1');
s1. addVariable('tipjar.title, 'Please Donate');
s1. addVariable('tipjar.text', 'If you like the audio, lyrics, and sonnets on this site, please help support the website by making a small donation');
s1. addVariable('tipjar.business', 'obiwood@obiwood@obadiahlyrics.com');
s1. addVariable('tipjar.show_pause', 'true');
s1. addVariable('tipjar.currency_code', 'CAD');
s1. addVariable('tipjar.return_url', 'http://obadiahlyrics.com/thank-you.php');
s1. addVariable('backcolor', '4E6D82');
s1. addVariable('frontcolor', 'FFFFFF');
s1. addVariable('lightcolor', '9FCEE8');
s1. addVariable('screencolor', '4E6D82');
s1. addVariable('playlist', 'bottom');
s1. addVariable('playlistsize', '180');
s1. addVariable('logo', 'uploads/images/logo.png');
s1.write('audioPlayer');
</script>
Nov. 27, 2008KP
kLink
Thank you. Although your format for displaying the code did not work (line breaks), the adjustments did.
Ok, so errors are now gone.
I uploaded 2 mp3 files for test purposes only, and when you go to http://obadiahlyrics.com/uploads/audio/That%27s%20The%20Way%20It%20Is.mp3, the audio loads and plays.
Although I now see the playlist areas, I cannot read the content. And when I click in the space where I would imagine the list to be, I still get an error. changing the flash version from 9 to 9.0.124 helped in loading the playlist area.
when you say:
As soon as you start using a playlist, all of the File Properties:
[{( Reference: http://code.jeroenwijering.com/trac/wiki/FlashVars#Fileproperties )}]
MUST come from the equivalent playlist elements:
[{( Reference: http://code.jeroenwijering.com/trac/wiki/FlashFormats#Playlistformats )}].
I'm not clear on what this means exactly. Clarification, please. Are we talking about a separate file or the info that each mp3 should have? if latter, this may prove to be difficult as the file that will showcaseswill be done by the client and he is a novice. The sounds represent possible tunes for the lyrics on the site. So he'll be converting all his home recordings analog files to mp3. When he exports the mp3 files, are these the requirements he should adhere to for proper listing of the files in the playlist?
Can spaces in the file name cause problems?
Oooh, we're so close, I can taste it
current code is:
<script type="text/javascript">
var s1 = new SWFObject('/uploads/audio/player.swf','mp3','500','256','9.0.124');
s1.addParam("allowscriptaccess","always");
s1.addParam('allowfullscreen','false');
s1. addParam('flashvars','file=playlist.php&type=sound&backcolor=4E6D82&screencolor=4E6D82&frontcolor=ffffff&lightcolor=9FCEE8&playlist=right&playlistsize=300&displaywidth=200&controlbarsize=20&bufferlength=1&displayclick=play&logo=uploads/images/logo.png&plugins=tipjar-1&tipjar.title=Please Donate&tipjar.text=If you have enjoyed the audio, lyrics, and sonnets provided, please help support the website by making a small donation&tipjar.business=obiwood@obadiahlyrics.com&tipjar.show_pause=true&tipjar.currency_code=CAD&tipjar.return_url=http://obadiahlyrics.com/thank-you.php');
s1.write('audioPlayer');
</script>
I've never done this before, so thanks for your help.
Nov. 27, 2008kLink
"Are we talking about a separate file or the info that each mp3 should have?"We're talking about the elements of a playlist track, such as the title. If you use a playlist, all of the File Properties that you use must come from the playlist. There is really only one required element, and that is the location element. Of course, you really should also have a Title and you might as well have a Description (playlist annotation element) since the space is there.
Spaces in filenames don't cause problems.
You probably can't read the playlist content (Title & Description) because of the colors that you have chosen. Try changing them or temporarily comment them out so the defaults are used. Then pick combinations that work, using the color picker in the Wizard linked at the top of this page.
I can't find your playlist to check it. Please post a link to it.
Nov. 27, 2008KP
kLink:
So, if I understand you correctly, it is not enough to place the player and give it a file param of playlist.php. I also need to add an xml playlist that contains the file name, title, description, etc. Correct?
I'm using cmsms, and the good folks there have created a module to play that embeds the neolao flv and mp3 player. I understand it now works with JW Player, I just installed it and although I got to the same stage i'm in now a lot faster, I'm still not able to run a php playlist.
starting to get worried that this is not feasible.
Nov. 28, 2008kLink
playlist.php should be (and probably is) a PHP script that generates a playlist in some format (hopefully it's compatible with the JW FLV Media Player) by looking through a directory of media files. You will have to determine what playlist.php does by looking through the documentation for your CMS.
Nov. 28, 2008KP
Hi klink:
I decided not to use the cmsms module. I'm sticking with what we have put together thus far and what you've taken such pain to explain to me. what you see on this page (http://obadiahlyrics.com/audio.php), is the sum of our efforts thus far, but as you can see, the titles still don't show up and do not play. I've gotten rid of all the errors per your post of 19.11.2008
in uploads/audio/, I have:
player.swf
2 audio files
playlist.php - as provided by you and as follows:
<?php
// set this to a creator name
$creator = "Obi Wood";
// search for mp3 files
$filter = ".mp3";
// path to the directory you want to scan
// "./" = current directory
$directory = "./";
// URL to files
$url = "http://obadiahlyrics.com/uploads/audio";
/////////////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false))
{
//////////////////////////////////////////// Windows debug code \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// unset($output);
// exec('stat -t ' . escapeshellarg($entry), $output);
// print "<pre>";
// print_r($output);
// exit;
// $output = explode(' ', $output[0]);
// $items[$entry]['mtime'] = $output[10];
//////////////////////////////////////////// Windows debug code \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//...Windows normal code - sorting by mtime
// $items[$entry]['mtime'] = filemtime($entry);
//...Linux/Unix code - sorting by mtime
// There is an option in the "stat" command to return the MAC timestamps of a file in epoch time,
// where Access/Modify/Change are given in format %X/%Y/%Z.
// $items[$entry]['mtime'] = exec('stat -c %Y ' . escapeshellarg("{$directory}/{$entry}"));
//...Windows/Linux/Unix normal code - sorting by filename
$items[$entry] = $entry;
}
}
$d->close();
// reverse sort - latest first
// arsort($items);
// normal sort - alphabetically by filename
asort($items);
}
// xml header and opening tags
header("content-type:text/xml;charset=utf-8");
print <<<END
<?xml version='1.0' encoding='utf-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>Obadiah Lyrics - Sample Audio</title>
<trackList>
END;
// loop through the array to build the track
foreach($items as $key => $value)
{
$title = substr($key, 0, strlen($key) - 4);
print <<<END
<track>
<creator>$creator</creator>
<title>$title</title>
<location>$url/$key</location>
</track>
END;
}
// closing tags
print <<<END
</trackList>
</playlist>
END;
?>
On the page audio.php, I have this code:
<script type="text/javascript">
var s1 = new SWFObject('/uploads/audio/player.swf','mp3','500','256','9.0.124');
s1.addParam("allowscriptaccess","always");
s1.addParam('allowfullscreen','false');
s1. addParam('flashvars','file=playlist.php&type=sound&backcolor=4E6D82&screencolor=4E6D82&frontcolor=ffffff&lightcolor=9FCEE8&playlist=right&playlistsize=300&displaywidth=200&controlbarsize=20&bufferlength=1&displayclick=play&logo=uploads/images/logo.png&plugins=tipjar-1&tipjar.title=Please Donate&tipjar.text=If you have enjoyed the audio, lyrics, and sonnets provided, please help support the website by making a small donation&tipjar.business=obiwood@obadiahlyrics.com&tipjar.show_pause=true&tipjar.currency_code=CAD&tipjar.return_url=http://obadiahlyrics.com/thank-you.php');
s1.write('audioPlayer');
</script>
In the head, i'm referencing SWFObject.js
So why am i still not able to see the list of audio files and play them? If you've explained it and I'm not getting, try explaining to me as if I was 5. Maybe something will sink in.
thanks for your patience.
Nov. 29, 2008kLink
Is this the correct URI for your playlist generator playlist.php?
http://obadiahlyrics.com/uploads/audio/playlist.php
If it is the correct URI, then you should be able to get a playlist file returned by copying and pasting the URI in your browser.
When I try to do that, I get a "403 Forbidden" error. Which usually means that the directory/file-execute permissions on your server are not set correctly.
Try to make sure that the permissions on http://obadiahlyrics.com/uploads/audio/ and playlist.phpare set correctly, then copy & paste each URI in your browser to test the Internet availability of each file.
http://obadiahlyrics.com/uploads/audio/swfobject.js -- OK v1.5
http://obadiahlyrics.com/uploads/audio/player.swf -- OK v4.1.60
http://obadiahlyrics.com/uploads/audio/playlist.php -- NOT OK - 403 Forbidden error
http://obadiahlyrics.com/uploads/audio/filename.mp3 -- NOT tested
http://obadiahlyrics.com/uploads/audio/filename.mp3 -- NOT tested
So it looks like swfobject.js and player.swf are OK. I didn't test the MP3s because I don't know their filenames. So for some reason, it is not possible to execute the PHP script, probably a file-execute permissions issue.
Nov. 29, 2008The Redentor
Warning: Line s1.addparam too long:
s1. addParam('flashvars','file=playlist.php&type=sound&backcolor=4E6D82&screencolor=4E6D82&frontcolor=ffffff&lightcolor=9FCEE8&playlist=right&playlistsize=300&displaywidth=200&controlbarsize=20&bufferlength=1&displayclick=play&logo=uploads/images/logo.png&plugins=tipjar-1&tipjar.title=Please Donate&tipjar.text=If you have enjoyed the audio, lyrics, and sonnets provided, please help support the website by making a small donation&tipjar.business=obiwood@obadiahlyrics.com&tipjar.show_pause=true&tipjar.currency_code=CAD&tipjar.return_url=http://obadiahlyrics.com/thank-you.php');
Remove parameters and text to reduce the line and obtain the correct functionality
Nov. 29, 2008kLink
See my post above, 19.11.2008. Use so.addVariable()
Nov. 30, 2008KP
KLink:
I have tested an audio file <http://obadiahlyrics.com/uploads/audio/I%20Will%20Survive.mp3>, and it plays
I have looked at the playlist <http://obadiahlyrics.com/uploads/audio/playlist.php> and NO errors only a blank screen (playlist permission is 644)
also, if I use s0.addVariable() or even s1.addVariable, I get the download link for Flash. the player disappears altogether.
<script type="text/javascript">
var s0 = new SWFObject('uploads/audio/player.swf', 'mp3', '400', '256', '9.0.124');
s0.addParam('allowscriptaccess', 'always');
s0.addParam('allowfullscreen', 'false');
s0. addVariable('file', 'obiwoodPlaylist.php);
s0. addVariable('type', 'sound');
s0. addVariable('plugins', 'tipjar-1');
s0. addVariable('tipjar.title, 'Please Donate');
s0. addVariable('tipjar.text', 'If you like the audio, lyrics, and sonnets on this site, please help support the website by making a small donation');
s0. addVariable('tipjar.business', 'obiwood@obadiahlyrics.com');
s0. addVariable('tipjar.show_pause', 'true');
s0. addVariable('tipjar.currency_code', 'CAD');
s0. addVariable('tipjar.return_url', 'http://obadiahlyrics.com/thank-you.php');
s0. addVariable('backcolor', '4E6D82');
s0. addVariable('frontcolor', 'FFFFFF');
s0. addVariable('lightcolor', '9FCEE8');
s0. addVariable('screencolor', '4E6D82');
s0. addVariable('playlist', 'right');
s0. addVariable('playlistsize', '200');
s0. addVariable('logo', 'uploads/images/logo.png');
s0.write('audioPlayer');
</script>
So I have reverted to using the addParam option and removed all excessive variables to do with the donation plugin.
I'm still at the same place.
There's got to be a better way. Could this have anything to do with the player? do i need to upgrade?
Nov. 30, 2008kLink
I still get a "403 Forbidden" error from: http://obadiahlyrics.com/uploads/audio/playlist.php
playlist.php should have permission of 755. See the explanation in section 4 here: http://www.zzee.com/solutions/unix-permissions.shtml
This has absolutely nothing to do with the player or the player code.
Sending a request from a browser for a playlist should return a valid playlist file.
Dec. 01, 2008Zenmaier
Another HD Flash player more easy to install and it includes a file/folder manager
flashuploaded.com or hdflashplayer.com, there's a Free version... I nstalled it in 5mn on my website and it works great.
Dec. 04, 2008KP
ZenMaler: would it work on a CMS? or would i have to use an external file? it looks complicated or at least the terminology is beyond my comprehension. I'll keep it in mind.
kLink: i agree it should ouput a playlist file, but it does not. I checked the permissions, and they are set to 755 according to file manager in cpanel. kLink, can you force refresh your cache and let me know if you still have the 403 forbidden error? I never had it.
this is my last try at this.
script on page is:
<script type="text/javascript">
var s0 = new SWFObject('/uploads/audio/player.swf', 'mp3', '420', '256', '9.0.124');
s0.addParam('allowscriptaccess', 'always');
s0.addParam('allowfullscreen', 'false');
s0. addVariable('file', '/uploads/audio/playlist.php');
s0. addVariable('type', 'sound');
s0. addVariable('playlist', 'right');
s0. addVariable('playlistsize', '250');
s0.addVariable('scrollsize','10');
s0. addVariable('backcolor', '4E6D82');
s0. addVariable('frontcolor', 'FFFFFF');
s0. addVariable('lightcolor', '9FCEE8');
s0. addVariable('screencolor', '4E6D82');
s0. addVariable('logo', '/uploads/images/logo.png');
s0.write('audioPlayer');
</script>
test files in http://obadiahlyrics.com/uploads/audio/
Heatwave.mp3
I Will Survive.mp3
player.swf
swfobject.js
playlist.php - your alpha sorted list - this file uses print command
testplaylist.php - php script as provided by AJAX at the top of this thread - this file uses echo command
in the Script, if I replace
s0. addVariable('file', '/uploads/audio/playlist.php');
with
s0. addVariable('file', '/uploads/audio/Heatwave.mp3');
The audio plays. I will try with an xml file. If that works, then there is something wrong either with the php file or the call to the php file.
playlist.php reads
<?php
// set this to a creator name
$creator = "Obi Wood";
// search for mp3 files
$filter = ".mp3";
// path to the directory you want to scan
// "./" = current directory
$directory = "./";
// URL to files
$url = "http://obadiahlyrics.com/uploads/audio";
/////////////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false))
{
//////////////////////////////////////////// Windows debug code \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// unset($output);
// exec('stat -t ' . escapeshellarg($entry), $output);
// print "<pre>";
// print_r($output);
// exit;
// $output = explode(' ', $output[0]);
// $items[$entry]['mtime'] = $output[10];
//////////////////////////////////////////// Windows debug code \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//...Windows normal code - sorting by mtime
// $items[$entry]['mtime'] = filemtime($entry);
//...Linux/Unix code - sorting by mtime
// There is an option in the "stat" command to return the MAC timestamps of a file in epoch time,
// where Access/Modify/Change are given in format %X/%Y/%Z.
// $items[$entry]['mtime'] = exec('stat -c %Y ' . escapeshellarg("{$directory}/{$entry}"));
//...Windows/Linux/Unix normal code - sorting by filename
$items[$entry] = $entry;
}
}
$d->close();
// reverse sort - latest first
// arsort($items);
// normal sort - alphabetically by filename
asort($items);
}
// xml header and opening tags
header("content-type:text/xml;charset=utf-8");
print <<<END
<?xml version='1.0' encoding='utf-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>Obadiah Lyrics - Sample Audio</title>
<trackList>
END;
// loop through the array to build the track
foreach($items as $key => $value)
{
$title = substr($key, 0, strlen($key) - 4);
print <<<END
<track>
<creator>$creator</creator>
<title>$title</title>
<location>$url/$key</location>
</track>
END;
}
// closing tags
print <<<END
</trackList>
</playlist>
END;
?>
testplaylist.php reads - from AJAX
<?php
/*
* This is a sample file that reads through a directory, filters the mp3/jpg/flv
* files and builds a playlist from it. After looking through this file, you'll
* probably 'get the idea' and'll be able to setup your own directory.
*
*/
// set this to a creator name
$creator = "Obi Wood";
// search for mp3 files. set this to '.flv' or '.jpg' for the other scripts
$filter = ".mp3";
// path to the directory you want to scan
// "./" = current directory
$directory = "./";
// URL to files
$url = "http://obadiahlyrics.com/uploads/audio";
/////////////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false))
{
$items[$entry]['mtime'] = filemtime($entry);
}
}
$d->close();
arsort($items);
}
// the playlist is built in an xspf format
// first, we'll add an xml header and the opening tags...
header("content-type:text/xml;charset=utf-8");
echo "<?xml version='1.0' encoding='utf-8'?>\n";
echo "<playlist version='1' xmlns='http://xspf.org/ns/0/'>\n";
echo " <title>Sample Sounds for Lyrics and Sonnets</title>\n";
echo " <info>" . $url . "</info>\n";
echo " <trackList>\n";
// ...then we loop through the array...
foreach($items as $key => $value)
{
$title = substr($key, 0, strlen($key) - 4);
echo " <track>\n";
// echo " <creator>" . $creator . "</creator>\n";
echo " <title>" . $title . "</title>\n";
echo " <location>" . $url . '/' . $key . "</location>\n";
echo " <info>" . $url . "</info>\n";
echo " </track>\n";
}
// ...and last we add the closing tags
echo " </trackList>\n";
echo "</playlist>\n";
/*
* That's it! You can feed this playlist to the SWF by setting this as it's 'file'
* parameter in your HTML page.
*/
?>
Thank you for all your assistance. I realize by review this thread that i've taken up much of your time.
Dec. 04, 2008kLink
I still get the "403 Forbidden" error. Somethng is still wrong with your server setup.
I copied and pasted your playlist.php code from your most recent post. It ran perfectly on my server without a single change. It's really quite "plain vanilla" code now, so it should run on your server.
Dec. 05, 2008KP
Hi Klink:
We now have it working. There were a few issues, file path and permission being the big ones. One last question. If you go to http://obadiahlyrics.com/audio.php you'll notice the extra spacing between the titles, how do I reduce these? is this a stylesheet issue or something else. I checked the php file and could not find where I needed to adjust.
For the purpose of anyone out there that is looking for a dynamic list and might be experiencing the same issue, here's what to do:
FTP the following files into the folder where your audio will reside:
player.swf
swfobject.js
playlist.php
youraudio.mp3
on the page you want to display the player, place this code:
<div id="player" align="center"><a href="http://www.macromedia.com/go/getflashplayer">Get the Flash Player</a>, a free download, to see movies on this site.</div>
<script type="text/javascript" src="http://yourdomain.com/uploadsfolder/swfobject.js"></script>
<script type="text/javascript">
var so = new SWFObject('http://yourdomain.com/uploadsfolder/player.swf','mp3','450','200','9.0.124');
so.addParam('allowscriptaccess','always');
so.addParam('allowfullscreen','false');
so.addParam('flashvars','file=http://yourdomain.com/youruploadfolder/playlist.php&playlist=bottom');
so.write('player');
</script
You can place the call to the js file in the head section of your page and you can use relative path. You can also use relative path for var so.
if adding color changes, add them to the flashvars after 'bottom' and be sure to start with an &. Colors must be in Hex without the #. the path to playlist.php must be absolute
The code for playlist.php for Linux/Unix with Alpha sort order is:
<?php
// set this to a creator name
$creator = "Myself";
// search for mp3 files
$filter = ".mp3";
// path to the directory you want to scan
// "./" = current directory
$directory = "./";
// URL to files
$url = "http://www.yourdomain.com/uploadforler/";
/////////////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false))
{
//////////////////////////////////////////// Windows debug code \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// unset($output);
// exec('stat -t ' . escapeshellarg($entry), $output);
// print "<pre>";
// print_r($output);
// exit;
// $output = explode(' ', $output[0]);
// $items[$entry]['mtime'] = $output[10];
//////////////////////////////////////////// Windows debug code \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//...Windows normal code - sorting by mtime
// $items[$entry]['mtime'] = filemtime($entry);
//...Linux/Unix code - sorting by mtime
// There is an option in the "stat" command to return the MAC timestamps of a file in epoch time,
// where Access/Modify/Change are given in format %X/%Y/%Z.
// $items[$entry]['mtime'] = exec('stat -c %Y ' . escapeshellarg("{$directory}/{$entry}"));
//...Windows/Linux/Unix normal code - sorting by filename
$items[$entry] = $entry;
}
}
$d->close();
// reverse sort - latest first
// arsort($items);
// normal sort - alphabetically by filename
asort($items);
}
// xml header and opening tags
header("content-type:text/xml;charset=utf-8");
print <<<END
<?xml version='1.0' encoding='utf-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>PHP Sample Audio Alpha Sorted</title>
<trackList>
END;
// loop through the array to build the track
foreach($items as $key => $value)
{
$title = substr($key, 0, strlen($key) - 4);
print <<<END
<track>
<creator>$creator</creator>
<title>$title</title>
<location>$url/$key</location>
</track>
END;
}
// closing tags
print <<<END
</trackList>
</playlist>
END;
?>
Be sure to set permission for playlist.php to 0755. If the playlist does not show up, try uploading from cpanel's file manager and then setting permissions while in cpanel. That seems to do the trick. I'm assuming you are on a Linux server and your host offers cpanel to help you manage your account.
Works with jwplayer 4.2+
Dec. 05, 2008kLink
@KP,
Fan—FREAKIN—tastic!!!
On the issues with the size of the playlist tracks; you have two choices:
1) http://www.jeroenwijering.com/?item=Skinning_the_JW_Player
2) http://www.longtailvideo.com/AddOns/productpage.html?addon=51&q=&category=skins Simple, one line per track skin with no thumbnails.
Dec. 12, 2008XKG Media
Hi Guys,
Where can i download the tipjar plugin?
Please post a link....
Thanks in advance.
Dec. 12, 2008kLink
All Plugins: http://www.longtailvideo.com
Dec. 16, 2008Water
Hello guys im tying to set up and playlist generator on my site. Im having trouble i don't know how does it work. i tried using the code above saved it as php and then called it from my browser to see what happen this is what im getting
This XML file does not appear to have any style information associated with it. The document tree is shown below.
−
<playlist version="1">
<title>bachata</title>
<info>/media player</info>
−
<trackList>
<br/>
<b>Warning</b>
: Invalid argument supplied for foreach() in
−
<b>
/home/kalleje/public_html/media player/bachata.php
</b>
on line
<b>53</b>
<br/>
</trackList>
</playlist>
Ajax if you are around please help me on this
Dec. 16, 2008kLink
Post the PHP playlist generator code that you are using and also a link to the playlist generator on your site, and I'll help you straighten it out.
Dec. 17, 2008water
ok thank you kLink
here is the link to the php
http://www.kallejero.com/MusicPlayer/playlistgenerator.php
and here is the code im using
<?php
/*
* This is a sample file that reads through a directory, filters the mp3/jpg/flv
* files and builds a playlist from it. After looking through this file, you'll
* probably 'get the idea' and'll be able to setup your own directory.
*
*/
// set this to a creator name
$creator = "Kallejero";
// search for mp3 files. set this to '.flv' or '.jpg' for the other scripts
$filter = ".mp3";
// path to the directory you want to scan
// "./" = current directory
$directory = "/downloads/Bachata/";
// URL to files
$url = "http://www.kallejero.com/media player";
/////////////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false))
{
$items[$entry]['mtime'] = filemtime($entry);
}
}
$d->close();
arsort($items);
}
// the playlist is built in an xspf format
// first, we'll add an xml header and the opening tags...
header("content-type:text/xml;charset=utf-8");
echo "<?xml version='1.0' encoding='utf-8'?>\n";
echo "<playlist version='1' xmlns='http://xspf.org/ns/0/'>\n";
echo " <title>Bachata</title>\n";
echo " <info>" . $url . "</info>\n";
echo " <trackList>\n";
// ...then we loop through the array...
foreach($items as $key => $value)
{
$title = substr($key, 0, strlen($key) - 4);
echo " <track>\n";
echo " <creator>" . $creator . "</creator>\n";
echo " <title>" . $title . "</title>\n";
echo " <location>" . $url . '/' . $key . "</location>\n";
echo " <image>" . $url . '/' . $title . ".jpg</image>\n";
echo " <info>" . $url . "</info>\n";
echo " </track>\n";
}
// ...and last we add the closing tags
echo " </trackList>\n";
echo "</playlist>\n";
/*
* That's it! You can feed this playlist to the SWF by setting this as it's 'file'
* parameter in your HTML page.
*/
?>
Dec. 21, 2008Water
@ KLink
Hey KLink when you get a chance help me out i need to get this done. Or Ajax or anybody elso who think can help me fix it Thanks
Dec. 22, 2008kLink
@Water,
Your playlist code is OK. I updated it a bit, but the basic code was correct.
You probably just have an incorrect path. Unless you are doing external file access, the PHP script uses the local file system paths on the server, NOT web server paths from document root. The GOTCHA is that some hosts, running virtual hosting, insert a hidden, invisible directory in the path. So the best way to make a path, is to start with the current directory "./" that's period forward slash (the location of the PHP script) and assemble the path from there.
Without knowing the the directory structure on yur server, I can't give yo the exact path, but start with the current directory where the script resides and assemble a relative path to the media files.
<?php
// call with: http://www.mydomain.com/path/thisscriptname.php
// set this to a creator name
$creator = 'Kallejero';
// search for mp3 files set this to '.flv' or '.jpg' for the other media types
$filter = '.mp3';
// local filesystem path to the directory you want to scan "./" is the current directory
$directory = './downloads/Bachata/'; // if this script in in the directory "downloads"
// URL to files
$url = 'http://www.kallejero.com/media player';
//////////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false))
{
$items[$entry]['mtime'] = filemtime($entry);
}
}
$d->close();
arsort($items);
}
// xml header and the opening tags...
header("content-type:text/xml;charset=utf-8");
print <<<END
<?xml version='1.0' encoding='utf-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>Bachata</title>
<info>$url</info>
<trackList>
END;
// loop through the array
foreach($items as $key => $value)
{
$title = substr($key, 0, strlen($key) - 4);
print <<<END
<track>
<creator>$creator</creator>
<title>$title</title>
<location>$url/$key</location>
<image>$url/$title.jpg</image>
<info>$url</info>
</track>
END;
}
// closing tags
print <<<END
</trackList>
</playlist>
END;
?>
Dec. 23, 2008Water
@ Link
Thank you Link for your replied. Im trying to figure out what im doing wrong I copied your code and replaced the one i have but still same problem. Here are some picture of my root directory and the directory where i have the player with the script and also where i have my mp3 files. Hope this help you figure out.
Root pic
http://img376.imageshack.us/img376/9053/root1ri9.jpg
MP3 files
http://img508.imageshack.us/img508/4170/mp3files2it4.jpg
The Script
http://img508.imageshack.us/img508/214/scriptphotoze1.jpg
Dec. 23, 2008kLink
OK, I'll check your directory structure in the next day or two.
Dec. 23, 2008kLink
http://img376.imageshack.us/img376/9053/root1ri9.jpg
You are showing me the web server directory structure —NOT— the server OS file system directory structure which PHP uses.
You could possibly use:
$directory = '../downloads/Bachata/';
It would be better to put the script in downloads and use:
$directory = './Bachata/';
Although not prohibited by this script, it's never a good idea to allow someone to walk upwards in your directory structure.
Dec. 23, 2008water
@ Link ok i tried
$directory = '../downloads/Bachata/';
and this is what i get now
Warning: filemtime() [function.filemtime]: stat failed for Xtreme 10 Super Fanatica.mp3 in /home/XXXX/public_html/XXX/media player/playlistgenerator.php on line 29
i get this for every song. so basicaly i get a list or the same error with the dif mp3 names
Dec. 23, 2008kLink
OK, you must be on a *nix-based server.
Sometimes they have a problem with the filemtime() function.
If you look at the code that I posted above on November 14, 2008, you will see a special section for Linux below this comment:Uncomment the line above in bold and comment out the line below in bold which is for Windows and normal *nix:
//...Linux/Unix code - sorting by mtime
// There is an option in the "stat" command to return the MAC timestamps of a file in epoch time,
// where Access/Modify/Change are given in format %X/%Y/%Z.
$items[$entry]['mtime'] = exec('stat -c %Y ' . escapeshellarg("{$directory}/{$entry}"));
//...Windows/Linux/Unix normal code - sorting by filename
// $items[$entry] = $entry;
It's all explained in my posts above, so I'm not going to repeat them here.
Dec. 23, 2008water
@ Link
Hey link thank it look like this its getting better now. but i still have a problem the playlist its now working. when i call the play list i get everythign but i noted this like dash before track and before location
<track>
<creator>water</creator>
<title>Geovanny Polanco - Limpiate El Boss</title>
−
<location>
http://www.mysic.com/Music/Geovanny Polanco - Limpiate El Boss.mp3
</location>
</track>
−
<track>
they player just scan through all the track returning no audio. if i click on any track they won't work. Any idea why?
Dec. 23, 2008kLink
If you are seeing the dash in Internet Explorer, it is just a symbol to click on to collapse the track. When you View, Source you should see a good playlist.
When I access your playlist generator at:I still see the filemtime warning. Where is your working playlist generator located?
http://www.kallejero.com/media%20player/playlistgenerator.php
The location that you posted above:http://www.mysic.com/Music/Geovanny Polanco - Limpiate El Boss.mp3 is not a valid URI to a MP3 file.
If you have those URIs in your playlist, then you need to change this line from:// URL to filesto:
$url = 'http://www.kallejero.com/media player';// URL to filesso you get a location URI that looks like this:
$url = 'http://www.kallejero.com/downloads/Bachata';<location>http://www.kallejero.com/downloads/Bachata/Geovanny Polanco - Limpiate El Boss.mp3</location>
It's very confusing because you have many different URIs posted now.
Dec. 24, 2008water
oh sorry i change the name i actually created a new one
the link for the new one is this one
http://www.kallejero.com/media%20player/autolist.php
sorry i had delete some entry on that link. but you can see the new playlist using the address above
http://www.mysic.com/Music/Geovanny Polanco - Limpiate El Boss.mp3.
Dec. 24, 2008water
@ link
If you have those URIs in your playlist, then you need to change this line from:// URL to files
$url = 'http://www.kallejero.com/media player';to:
That actually was my problem i wasn't specify the path to the file directory. Link you are the man. one more question. is there a way to have the playlist grab the creator name from the file?? because i want to show the artist name as the creator.
Dec. 24, 2008kLink
Add the line in bold for the Creator name:
// loop through the array
foreach($items as $key => $value)
{
$creator = substr($key, 0, strpos($key, ' - '));
$title = substr($key, 0, strlen($key) - 4);
Dec. 24, 2008water
@ Link
Thank you very much. I really appreciate your help. hope you have a merry Christmas you and your family. Oh question are you a programmer?
Dec. 24, 2008kLink
"...are you a programmer? Maybe, kinda, sorta.
Merry Christmas to you and yours.
Dec. 25, 2008water
@ link LOL
So if in the future i need some extra help i may come looking for you. ofcourse i will have to pay you for extra work. lol
Dec. 25, 2008kLink
You can contact me with the username "wellitsme" and the rest of the normal Google mail address.
Dec. 26, 2008water
i will add that to my address book thank again
Dec. 30, 2008water
@ Link
Hey link how you doing? I have another question regarding the playlist generator. how can i make it to show the title without the creator in from? for example the song name its goes like this "Jay Z - 99 problem.mp3" so right now the way my playlist it will look like this on my player. Creator = Jay Z Title= Jay Z - 99 Problem. to get the Jay Z as the creator you told me to use this code // loop through the array
foreach($items as $key => $value)
{
$creator = substr($key, 0, strpos($key, ' - '));
$title = substr($key, 0, strlen($key) - 4); so how can i get the title to be display after the - ?
Dec. 30, 2008TinyB
$title = substr($key, (strpos($key, ' - ') + 3), strlen(substr($key, (strpos($key, ' - ') + 3))) - 4);
Jan. 01, 2009water
@ TinyB
Thank you very much, that work fine. Happy new year
Jan. 07, 2009KP
@ link
it's been a while. how's 2009 starting out for you?
I have a quick question. I had my audio with playlist.php working just fine. I'm finally about to launch this site and decided to check all the major components. the audio is no longer visible.
if you go to http://obadiahlyrics.com/uploads/audio/playlist.php you'll notice the playlist is being generated, but when you go to http://obadiahlyrics.com/uploads/audio.php you'll only see the get flash download link.
I know that my host recently upgraded from php 5.2.5
to 5.2.8 and I have asked him to check in case it is a server issue. Do you know if anything might have changed on your end or perhaps point me in a new direction?
much appreciated it and happy new year. if you don't mind, i'd like to also add your name to my gmail address book. thanks again
Jan. 07, 2009textOverflow
@KP,
All of the "s-something-" variables have to be the same. Somehow, the first one got to be "so" or all of the others got to be "s0".
<script type="text/javascript">
var so = new SWFObject('/uploads/audio/player.swf', 'mp3', '360', '420', '9.0.124');
s0.addParam('allowscriptaccess', 'always');
s0.addParam('allowfullscreen', 'false');
s0.addVariable('file', 'http://obadiahlyrics.com/uploads/audio/playlist.php');
s0.addVariable('skin', 'http://obadiahlyrics.com/uploads/audio/simple.swf');
s0.addVariable('playlist', 'bottom');
s0.addVariable('playlistsize', '400');
s0.addVariable('scrollsize', '10');
s0.addVariable('backcolor', 'E6E6E6');
s0.addVariable('frontcolor', '6289A3');
s0.addVariable('lightcolor', '810F12');
s0.write('player');
</script>
Jan. 07, 2009KP
textOverflow
Bless you. I went over that so many times I plum didn't see it. now I can launch. thank you.
Jan. 10, 2009inthemix
Using this code and saved as playlist.php in this folder on my site. http://www.inthemixusa.com/video-gallery. Of course there are sub directories in the video-gallery directory where my flv files are. I call for the php from the html script. Here it is:
<script type='text/javascript' src='http://www.nlvtech.com/video-gallery/swfobject.js'></script>
<div id="mediaspace">This div will be replaced</div>
<script type='text/javascript'>
var s1 = new SWFObject('http://www.nlvtech.com/video-gallery/player.swf','ply','640','260','9','#ffffff');
s1.addParam('allowfullscreen','true');
s1.addParam('allowscriptaccess','always');
s1.addParam('wmode','opaque');
s1.addParam('flashvars','file=http://www.nlvtech.com/video-gallery/playlist.php&playlist=right&playlistsize=280&streamer=lighttpd&fullscreen=true&backcolor=000000&frontcolor=ffffff');
s1.write('mediaspace');
</script>
The problem i am having is when I run the script I am getting a "No Valid File Type Found In This Playlist" error.
What am I doing wrong?
Here is my code called playlist.php
<?php
/*
* This is a sample file that reads through a directory, filters the mp3/jpg/flv
* files and builds a playlist from it. After looking through this file, you'll
* probably 'get the idea' and'll be able to setup your own directory.
*
*/
// set this to a creator name
$creator = "In The Mix USA";
// search for mp3 files. set this to '.flv' or '.jpg' for the other scripts
$filter = ".mp3";
// path to the directory you want to scan
// "./" = current directory
$directory = "./";
// URL to files
$url = "http://www.inthemixusa.com/video-gallery";
/////////////////////////// no user configuration variables below this
\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false))
{
$items[$entry]['mtime'] = exec ('stat -c %Y '. escapeshellarg ($entry));
}
}
$d->close();
arsort($items);
}
// the playlist is built in an xspf format
// first, we'll add an xml header and the opening tags
echo "<?xml version='1.0' encoding='utf-8'?>\n";
echo "<playlist version='1' xmlns='http://xspf.org/ns/0/'>\n";
echo " <title>Sample PHP Generated Playlist</title>\n";
echo " <info>" . $url . "</info>\n";
echo " <trackList>\n";
// ...then we loop through the array...
foreach($items as $key => $value)
{
$title = substr($key, 0, strlen($key) - 4);
echo " <track>\n";
echo " <creator>" . $creator . "</creator>\n";
echo " <title>" . $title . "</title>\n";
echo " <location>" . $url . '/' . $key . "</location>\n";
echo " <info>" . $url . "</info>\n";
echo " </track>\n";
}
// ...and last we add the closing tags
echo " </trackList>\n";
echo "</playlist>\n";
/*
* That's it! You can feed this playlist to the SWF by setting this as it's 'file'
* parameter in your HTML page.
*/
?>
Jan. 10, 2009lefTy
The playlist generator script that you are using does not read sub-directories.
Some options are:
1) you could specify a sub-directory in the script,
2) you could send a sub-directory in a parameter when you call the playlist generator script,
3) you could place a copy of the script in each sub-directory, then call that copy when you wanted a playlist of media files from that particular sub-directory,
4) use a playlist generator script that uses PHP's recursive directory iterator to iterate through the sub-directories (you will get ALL of the media files from ALL of the sub-directories in one playlist).
Also, just in case you're not aware of it, the playlist generator script that you are using is intended to sort the playlist by last-modified time, latest first, and the particular code that you are using:$items[$entry]['mtime'] = exec ('stat -c %Y '. escapeshellarg ($entry));is for a server running a *nix OS.
Jan. 10, 2009inthemix
Thanks lefTy for your quick response. I think there is still a problem with the script because I moved one of my flv files to the same directory as the player.swf and the playlist.php file and still no luck. Same error. I need someone to get me back to the basics. If I can't get the php to read the flv in the same directory then I don't know where to start.
Jan. 10, 2009inthemix
And I forgot to ask what the correct script would be to run on my server. You stated that the playlist generator script is not intended for what I am trying to use it for.
Jan. 10, 2009lefTy
I need more details before I can give you an alternate script.
What do you want to do? 1, 2, 3, 4, from above —OR— none of the above?
What is your server OS?
Jan. 10, 2009inthemix
I would like to use procedure #4. As far as what my server OS is I am not sure. I use a company called Start Logic and have virtual server that I use. Is there and easy way to find out?
Jan. 10, 2009lefTy
Best way is to ask them.
You need to confirm that:
1) you can execute PHP scripts,
2) that they have PHP5,
3) if the OS is Windows or *nix.
Workarounds:
1) if they don't allow you to execute PH scripts, find a different host,
2) if they don't have PHP5, I have posted a recursive script that works on PHP4,
3) if you don't want to sort the files by mtime, then the OS doesn't matter.
Sample scripts: http://www.longtailvideo.com/jw/?search=recursivedirectoryiterator
Probably the latest code: http://www.longtailvideo.com/support/forum/Modules/9447/Read-Sub-folder-Sub-directory#msg86929
Live demo: http://www.willswonders.myip.org/php/php_readdir_playlist_jpg_simple.php
Jan. 11, 2009inthemix
Thanks again lefTY. I have abandoned the hope of reading through all my subdirectories and have gone to the old fashioned method of using a .xml playlist. You think that would have done the trick. Nope. I created the .xml file pointing it to two of my .flv files. When running the html script the player does load with the playlist on the bottom. The player has the triangle play button on the screen but it will not play either of the two .flv files.
Once again here are the two scrips.
First the html:
<script type='text/javascript' src='http://www.nlvtech.com/video-gallery/swfobject.js'></script>
<div id="mediaspace">This div will be replaced</div>
<script type='text/javascript'>
var s1 = new SWFObject('http://www.nlvtech.com/video-gallery/player.swf','ply','470','470','9','#');
s1.addParam('allowfullscreen','true');
s1.addParam('allowscriptaccess','always');
s1.addParam('wmode','opaque');
s1.addParam('flashvars','file=http://www.nlvtech.com/video-gallery/playlist.xml&playlist=bottom&skin=http://www.longtailvideo.com/jw/upload/simple.swf&backcolor=ffffff&frontcolor=000000&lightcolor=0099cc');
s1.write('mediaspace');
</script>
Now for the .xml script:
<?xml version="1.0" encoding="utf-8"?>
<playlist version="1" xmlns="http://xspf.org/ns/0/">
<trackList>
<track>
<title>10-24-08 Gamma Phi Beta Sororiety Formal</title>
<annotation>Video #1</description>
<location>http://www.nlvtech.com/video-gallery/10-24-08 Gamma Phi Beta Sororiety Formal/GammaPhiBeta0001.flv</location>
<image> </image>
<info>http://www.inthemixusa.com</info>
</track>
<track>
<title>10-24-08 Gamma Phi Beta Sororiety Formal</title>
<annotation>Video #2</description>
<location>http://www.nlvtech.com/video-gallery/10-24-08 Gamma Phi Beta Sororiety Formal/GammaPhiBeta0002.flv</location>
<image> </image>
<info>http://www.inthemixusa.com</info>
</track>
</trackList>
</playlist>
Thank you for all your help.
Jan. 11, 2009lefTy
Your opening and closing tags have to match.
Change this:<annotation>Video #2</description>
to this:<annotation>Video #2</annotation>
Jan. 18, 2009Anthony
Alright......I must be over looking something major.
I have been useing JW Player for a shoutcast stream for a while now but I've never had a reason for a playlist.
I am now trying to play all the backup audio that is in a directory. The php script works great (the fist code posted).
Now what? What am i over looking to get the player to play the php script?
This is what i have so far, i just tried modifying the code used by my streaming player....
<!-- Player Start -->
<script type="text/javascript" src="swfobject.js"></script>
<p id="player"><strong><a href="http://www.macromedia.com/go/getflashplayer">Get Flash</a> to see this player.</strong><br />
<script type="text/javascript">
var s1 = new SWFObject("player.swf","mp1","275","200","9","#2b405a");
s1.addParam("allowfullscreen","false");
s1.addParam("allowscriptaccess","always");
s1.addParam("flashvars","file=http://www.obxairwaves.com/audiobackup/swf_playlist.php&type=mp3&volume=100&autostart=false&frontcolor=ffffff&lightcolor=66cc00&backcolor=222222&playlist=bottom");
s1.write("player");
</script>
<!-- Player End -->
The only thing i can think of is wrong is that the playlist is not in an xml format. Do i need the script to write to an xml file if so i have no idea how.
Jan. 18, 2009lefTy
The:type=mp3in your flashvars is killing it.
The default, if no type is specified, is a playlist.
If your files didn't have the mp3 extension, then you would specify a type of mp3 in each playlist track.
So, remove:&type=mp3 and it should work.
Jan. 18, 2009Water
@ TinyB, Link or Ajax or who ever know how to do this. How can i set my playlist generator to displayed the newest files first ? i want to play my latest mp3 first.
Jan. 18, 2009lefTy
Use the playlist generator posted on Dec. 22, that has:{code]$items[$entry]['mtime'] = filemtime($entry);[/code]
It does a reverse sort (latest first) on the file's last modified time.
If your PHP doesn't have filemtime and/or your server has a *nix OS, then find the version that has the *nix code instead of the Windows code.
Jan. 27, 2009Matthijs
How to make a playlist from external files? The directory is hosted on a different server, but accesible.
Jan. 27, 2009lefTy
Check back later...
I'll post some PHP code to read an external directory and generate a playlist.
Jan. 27, 2009lefTy
<?php
// This script reads an external directory, filters the mp3/jpg/flv files and builds a playlist.
// call with: http://www.mydomain.com/path/php_read_external_directory_playlist.php?dir=http://www.externaldomain.com/path/
// search for jpg files. set this to '.flv' or '.mp3' and so on, for the other file types
$filter = '.jpg';
$pattern = '#' . $filter . '#';
// path to the external directory you want to scan
$directoryurl = (isset($_GET['dir'])) ? strval($_GET['dir']) : 'http://www.externaldomain.com/path/';
// media file URL
$mediaurl = 'http://www.externaldomain.com/path/';
// info URL
$infourl = 'http://www.mydomain.com/path/';
/////////////////////////////////// - End of Configuration - \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// get directory listing
if($directoryarray = file($directoryurl))
{
foreach($directoryarray as $file)
{
preg_match("#<a href=\"(.*?)\">#", $file, $match);
$ps = strpos(strtolower($match[1]), $filter);
if (!($ps === false))
{
$items[] = $match[1];
}
}
}
sort($items);
// arsort($items);
// shuffle($items);
// XSPF playlist - xml header and opening tags
header("content-type:text/xml;charset=utf-8");
print <<<END
<?xml version='1.0' encoding='UTF-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>Sample PHP Generated Playlist</title>
<info>$infourl</info>
<trackList>
END;
// loop through the array and write the track elements
foreach($items as $key => $value)
{
$title = preg_replace($pattern, '', $value); // remove file extension
$title = preg_replace('#_#', ' ', $title); // change underscores to spaces
$title = preg_replace('#%20#', ' ', $title); // change %20 to spaces
$title = preg_replace('#%26#', '&', $title); // change & to &
print <<<END
<track>
<title>$title</title>
<location>$mediaurl$value</location>
<annotation>This is the description for all media files.</annotation>
<info>$infourl</info>
</track>
END;
}
// closing tags
print <<<END
</trackList>
</playlist>
END;
?>
Jan. 28, 2009water
@ lefTy
You said to you the code posted on dec 22. Thats actually my playlist but it doesn't have the code
{code]$items[$entry]['mtime'] = filemtime($entry);[/code]
can i add that and where? Dec 22 playlist look at it and tell me if you can find out a way to do it? of if you think i could use a dif playlist generator let know so i can try it. I also would like to call and image to be display for some induvidual artist. I read how to do it for each song by naming the image exactly the same as the song. but how about if i just want to call the image as the artist name? can it be done?
Jan. 28, 2009lefTy
@water,
Your code posted on Dec.22, 2008 already does have the the code for getting the file mtime on Windows.
You can use the artist's name for the image but you might need to extract it from the filename if it is in the standard MP3 format "Artist Name - Song Name.mp3".
I added the *nix code if you need it.
Reverse sort by file mtime, latest first. The creator's name is used for the image name.
<?php
// call with: http://www.mydomain.com/path/thisscriptname.php
// set this to a creator name
$creator = 'Kallejero';
// search for mp3 files set this to '.flv' or '.jpg' for the other media types
$filter = '.mp3';
// local filesystem path to the directory you want to scan "./" is the current directory
$directory = './downloads/Bachata/'; // if this script in in the directory "downloads"
$directory = './';
// URL to files
$url = 'http://www.kallejero.com/media player';
//////////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false))
{
/////////////////////////////////////// Windows debug code \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// unset($output);
// exec('stat -t ' . escapeshellarg($entry), $output);
// print "<pre>";
// print_r($output);
// exit;
// $output = explode(' ', $output[0]);
// $items[$entry]['mtime'] = $output[10];
/////////////////////////////////////// Windows debug code \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//...Windows normal code - sorting by mtime
$items[$entry]['mtime'] = filemtime($entry);
//...Linux/Unix code - sorting by mtime
// There is an option in the "stat" command to return the MAC timestamps of a file in epoch time,
// where Access/Modify/Change are given in format %X/%Y/%Z.
// $items[$entry]['mtime'] = exec('stat -c %Y ' . escapeshellarg("{$directory}/{$entry}"));
//...Windows/Linux/Unix normal code - sorting by filename
// $items[$entry] = $entry;
}
}
$d->close();
//...reverse sort - latest first
arsort($items);
//...normal sort - alphabetically by filename
//asort($items);
}
// xml header and the opening tags...
header("content-type:text/xml;charset=utf-8");
print <<<END
<?xml version='1.0' encoding='utf-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>Bachata</title>
<info>$url</info>
<trackList>
END;
// loop through the array
foreach($items as $key => $value)
{
// "Artist Name - Song Name.mp3"
preg_match('#(.*?) - (.*?)\\' . $filter . '#', $key, $match);
$creator = $match[1];
$title = $match[2];
print <<<END
<track>
<creator>$creator</creator>
<title>$title</title>
<location>$url/$key</location>
<image>$url/$creator.jpg</image>
<info>$url</info>
</track>
END;
}
// closing tags
print <<<END
</trackList>
</playlist>
END;
?>
<?xml version='1.0' encoding='utf-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>Bachata</title>
<info>http://www.kallejero.com/media player</info>
<trackList>
<track>
<creator>Artist Name</creator>
<title>Song Title</title>
<location>http://www.kallejero.com/media player/Artist Name - Song Title.mp3</location>
<image>http://www.kallejero.com/media player/Artist Name.jpg</image>
<info>http://www.kallejero.com/media player</info>
</track>
</trackList>
</playlist>
Jan. 31, 2009water
@ lefTy
Thanks for your reply. i tried that code but didn't work. i think i was having the same problem before with that code and Link Told me to use a different code. but here is the code im using and its working. I want to modify that code to get the latest uploaded song play first on the list, also if i can get individual pictures for each artist just by naming the pictures same as the artist name appear on the creator. oh artist - song name.mp3 so i want to be able to gran the artist name and mach it with the picture name and display that pictures if its possible. thank and here its my code.
<?php
// set this to a creator name
//$creator = "Sajoma City";
// search for mp3 files
$filter = ".mp3";
// path to the directory you want to scan
// "./" = current directory
$directory = "../downloads/Tipicos/";
// URL to files
$url = 'http://mysite.com/downloads/Tipicos';
/////////////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false))
{
//////////////////////////////////////////// Windows debug code \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// unset($output);
// exec('stat -t ' . escapeshellarg($entry), $output);
// print "<pre>";
// print_r($output);
// exit;
// $output = explode(' ', $output[0]);
// $items[$entry]['mtime'] = $output[10];
//////////////////////////////////////////// Windows debug code \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//...Windows normal code - sorting by mtime
// $items[$entry]['mtime'] = filemtime($entry);
//...Linux/Unix code - sorting by mtime
// There is an option in the "stat" command to return the MAC timestamps of a file in epoch time,
// where Access/Modify/Change are given in format %X/%Y/%Z.
$items[$entry]['mtime'] = exec('stat -c %Y ' . escapeshellarg("{$directory}/{$entry}"));
//...Windows/Linux/Unix normal code - sorting by filename
// $items[$entry] = $entry;
}
}
$d->close();
// reverse sort - latest first
// arsort($items);
// normal sort - alphabetically by filename
asort($items);
}
// xml header and opening tags
header("content-type:text/xml;charset=utf-8");
print <<<END
<?xml version="1.0" encoding="UTF-8" ?>
<playlist version="1" xmlns="http://xspf.org/ns/0/">
<info>http://sajomacity.com</info>
<trackList>
END;
// loop through the array to build the track
foreach($items as $key => $value)
{
$creator = substr($key, 0, strpos($key, ' - '));
$title = substr($key, (strpos($key, ' - ') + 3), strlen(substr($key, (strpos($key, ' - ') + 3))) - 4);
print <<<END
<track>
<creator>$creator</creator>
<title>$title</title>
<location>$url/$key</location>
<image>./tipico.jpg</image> // I set this to grap a default picture for every song on this Directory i want to be able to grap a picture with the artist name
</track>
END;
}
// closing tags
print <<<END
</trackList>
</playlist>
END;
?>
Jan. 31, 2009lefTy
I can add the code for using the Artist's Name as the image filename, to your existing, working code, but first I need to confirm that your MP3 files are named with the common MP3 filename format of:
"Artist Name - Song Title.mp3".
Jan. 31, 2009water
@ lefTy
Thanks lefTy yes all my mp3 are on this format. Jay Z - 99 problem.mp3 Eminem - Remember me.mp3 etc etc i try to have the name of the artist first them space dash space and song title.mp3 I think this code here is the one the set my player with the artist name first and then the title under. $creator = substr($key, 0, strpos($key, ' - ')); I just need to grab the artist pictures if i name the pictures just like the artist. Jay Z - 99 Problem.mp3 and then picture will be Jay Z.jpg
$title = substr($key, (strpos($key, ' - ') + 3), strlen(substr($key, (strpos($key, ' - ') + 3))) - 4);
Feb. 01, 2009lefTy
<?php
// search for mp3 files
$filter = '.mp3';
// path to the directory you want to scan
$directory = '../downloads/Tipicos/';
// URL to files
$url = 'http://mysite.com/downloads/Tipicos';
//////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\
//...read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false))
{
//...*nix code - sorting by mtime
//...There is an option in the "stat" command to return the MAC timestamps of a file in epoch time,
//...where Access/Modify/Change are given in format %X/%Y/%Z.
$items[$entry]['mtime'] = exec('stat -c %Y ' . escapeshellarg("{$directory}/{$entry}"));
}
}
$d->close();
//...reverse sort - latest first
//arsort($items);
//...normal sort - latest last
asort($items);
}
//...xml header and opening tags
header("content-type:text/xml;charset=utf-8");
print <<<END
<?xml version="1.0" encoding="UTF-8" ?>
<playlist version="1" xmlns="http://xspf.org/ns/0/">
<info>http://sajomacity.com</info>
<trackList>
END;
//..loop through the array to build the track
foreach($items as $key => $value)
{
//..."Artist Name - Song Name.mp3"
preg_match('#(.*?) - (.*?)\\' . $filter . '#', $key, $match);
$creator = $match[1];
$title = $match[2];
print <<<END
<track>
<creator>$creator</creator>
<title>$title</title>
<location>$url/$key</location>
<image>$url/$creator.jpg</image>
</track>
END;
}
//...closing tags
print <<<END
</trackList>
</playlist>
END;
?>
Feb. 06, 2009water
@ lefTy
Thank you very much it work great. I just have a question. in order for the image to work it need to be in the same directory as the mp3. Is there a way i can have the image on a separate folder? can i specify the code on where to look for the image? Image name still need to be same as mp3 artist name. just want to place all image on it own directory. Thanks again
Feb. 06, 2009lefTy
<image>$url/images/$creator.jpg</image>
Add whatever folder(s) you want in place of images.
Feb. 07, 2009water
@ lefTy
Ok i tried that but it didn't work. Ok i want to have the images inside a a directory right where the player and the listgenerator are locate. No in the same directory where the mp3 are. i have the mp3 on a download directory right at the root and i have my player on another directory on the root as well. so my directories structure look like this.
Root > Download > Here are my mp3
Root > Player > here is my player and the listganerator
and i want to create a directory inside the player directory just to store the images
so they way i have it its like this
Root > Player > images > Here are the jpg
i the code i change it to this
<image>$url/player/images/$creator.jpg</image>
but its not working
Feb. 08, 2009lefTy
OK, so look at the URI that will be assembled:$url/player/images/$creator.jpg
This will result in:
http://mysite.com/downloads/Tipicos/player/images/Jay Z.jpg
So call the playlist generator in your browser and see if the image URI is correct.
http://www.mysite.com/player/playlist_generator.php
Adjust all paths to match your current paths.
Feb. 09, 2009water
@ lefTy
Thank you for you quick reply. what i want to do is not to put any images inside the downloads directory. i want to create a separate directory just for images.
http://www.mysite.com/images/tipicos/Jay Z.jpg
if this is not possible i will have to do it the way you say. But the ready i don't want to put the images inside the download directory its because i have a component that will plublish into the front page any mp3, images, etc that i upload to that directory and i don't want to publish the images into my front page
Feb. 09, 2009lefTy
Then use an image URL.
<?php
// search for mp3 files
$filter = '.mp3';
// path to the directory you want to scan
$directory = '../downloads/Tipicos/';
// URL to files
$url = 'http://mysite.com/downloads/Tipicos';
// URL to images
$imageurl = 'http://mysite.com/images/Tipicos';
//////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\
//...read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false))
{
//...*nix code - sorting by mtime
//...There is an option in the "stat" command to return the MAC timestamps of a file in epoch time,
//...where Access/Modify/Change are given in format %X/%Y/%Z.
$items[$entry]['mtime'] = exec('stat -c %Y ' . escapeshellarg("{$directory}/{$entry}"));
}
}
$d->close();
//...reverse sort - latest first
//arsort($items);
//...normal sort - latest last
asort($items);
}
//...xml header and opening tags
header("content-type:text/xml;charset=utf-8");
print <<<END
<?xml version="1.0" encoding="UTF-8" ?>
<playlist version="1" xmlns="http://xspf.org/ns/0/">
<info>http://sajomacity.com</info>
<trackList>
END;
//..loop through the array to build the track
foreach($items as $key => $value)
{
//..."Artist Name - Song Name.mp3"
preg_match('#(.*?) - (.*?)\\' . $filter . '#', $key, $match);
$creator = $match[1];
$title = $match[2];
print <<<END
<track>
<creator>$creator</creator>
<title>$title</title>
<location>$url/$key</location>
<image>$imageurl/$creator.jpg</image>
</track>
END;
}
//...closing tags
print <<<END
</trackList>
</playlist>
END;
?>
Feb. 12, 2009Water
@ lefTy
Ok that work just fine Thank you very much
Feb. 12, 2009lefTy
You're welcome.
Good Luck!
Apr. 16, 2009Mike
I saw in this forum how to filter multiple formats
I want to filter mp3,jpg,swf,flv files
// search for mp3 files. set this to '.flv' or '.jpg' for the other scripts
$filter1 = ".mp3";
$filter2 = ".flv";
$filter3 = ".swf";
$filter4 = ".jpg";
further on in the script I put
$ps1 = strpos(strtolower($entry), $filter1);
$ps2 = strpos(strtolower($entry), $filter2);
$ps3 = strpos(strtolower($entry), $filter3);
$ps4 = strpos(strtolower($entry), $filter4);
if (!(((($ps4 === false) || ($ps4 === false) || ($ps4 === false) || ($ps4 === false)))))
I don't get the if stament working
Can anybody tell me whats wrong.
Complete script<?php
// Creert een xml playlist van een map met flv bestanden.
// set this to a creator name
$creator = "Wriktv";
// search for mp3 files. set this to '.flv' or '.jpg' for the other scripts
$filter1 = ".mp3";
$filter2 = ".flv";
$filter3 = ".swf";
$filter4 = ".jpg";
// path to the directory you want to scan
$directory = '../wriktv/';
// URL to files
$url = 'http://www.wrik.com/wriktv';
/////////////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps1 = strpos(strtolower($entry), $filter1);
$ps2 = strpos(strtolower($entry), $filter2);
$ps3 = strpos(strtolower($entry), $filter3);
$ps4 = strpos(strtolower($entry), $filter4);
if (!(((($ps4 === false) || ($ps4 === false) || ($ps4 === false) || ($ps4 === false)))))
{
$items[$entry]['mtime'] = filemtime($entry);
}
}
$d->close();
arsort($items);
}
// the playlist is built in an xspf format
// first, we'll add an xml header and the opening tags...
header("content-type:text/xml;charset=utf-8");
echo "<?xml version='1.0' encoding='utf-8'?>\n";
echo "<playlist version='1' xmlns='http://xspf.org/ns/0/'>\n";
echo " <title>xml playlist</title>\n";
echo " <info>" . $url . "</info>\n";
echo " <trackList>\n";
// ...then we loop through the array...
foreach($items as $key => $value)
{
$title = substr($key, 0, strlen($key) - 4);
echo " <track>\n";
echo " <creator>" . $creator . "</creator>\n";
echo " <title>" . $title . "</title>\n";
echo " <location>" . $url . '/' . $key . "</location>\n";
echo " <info>" . $url . "</info>\n";
echo " </track>\n";
}
// ...and last we add the closing tags
echo " </trackList>\n";
echo "</playlist>\n";
/*
* That's it! You can feed this playlist to the SWF by setting this as it's 'file'
* parameter in your HTML page.
*/
?>
Apr. 16, 2009robin
if (!(((($ps1 === false) || ($ps2 === false) || ($ps3 === false) || ($ps4 === false)))))
Apr. 19, 2009water
Hello i got everything just fine using different play list to generate music from different folder grabbing image from they corresponding artist. Now i want to know if they is a way i can have a play list generator to get the music from 3 different folder and also keep grabbing the images for the artist too??
Lefty if you are around tell me if this is possible
May. 06, 2009Chadwill
Thank you so much for this script AJAX!
Works great, and i also learnt a little php along the way
However i have a question tho.. after googling a lot it seems rather impossible..
what id like is to have multiple play list:
On our school we tape a lot of sessions, and serve them on a web page, for those werent able to attend for those sessions.
id like to have either a list of links or a dropdown list that lets you choose a playlist for a certain day/session
and id really like like to have our videos stored in diffrent paths/folder for easy management.
So somhow i need to change $directory variable and reload the same page, to get the new playlist
as i should get a diffrent playlist since the $directory variable i changed, and the script is generating a xml from another directory.
any advice?
--i must sound insane..
May. 06, 2009rick
@Chadwill,
See Jan. 27, 2009 post, above.
It has the code for requesting a directory and an example in the comments at the beginning of the script.
May. 07, 2009Chadwill
Thanks rick, i must have missed that one!
works great.
Is it possible to use this with xmoov.php ?
i have set the playlist.php to not output $mediaurl or $url so only the filename is passed on to streamer=moov.php, wich allready have a path variable set..
as shown here:
my player:
<script type='text/javascript'>
var s1 = new SWFObject('player.swf','player','900','480','9');
s1.addParam('allowfullscreen','true');
s1.addParam('allowscriptaccess','always');
s1.addParam('flashvars','file=playlist.php&streamer=http://mysite.com/xmoov.php&playlist=right&playlistsize=260&thumbsinplaylist=false&fullscreen=true&backcolor=ffffff&frontcolor=000000');
s1.write('1');
</script>
my xmoov.php:
<?
/*
xmoov-php 0.9
Development version 0.9.3 beta
by: Eric Lorenzo Benjamin jr. webmaster (AT) xmoov (DOT) com
originally inspired by Stefan Richter at flashcomguru.com
bandwidth limiting by Terry streamingflvcom (AT) dedicatedmanagers (DOT) com
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License.
For more information, visit http://creativecommons.org/licenses/by-nc-sa/3.0/
For the full license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode
or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.
*/
// SCRIPT CONFIGURATION
//------------------------------------------------------------------------------------------
// MEDIA PATH
//
// you can configure these settings to point to video files outside the public html folder.
//------------------------------------------------------------------------------------------
// points to server root
define('XMOOV_PATH_ROOT', './');
// points to the folder containing the video files.
define('XMOOV_PATH_FILES', './video/20082009/');
//------------------------------------------------------------------------------------------
// SCRIPT BEHAVIOR
//------------------------------------------------------------------------------------------
//set to TRUE to use bandwidth limiting.
define('XMOOV_CONF_LIMIT_BANDWIDTH', TRUE);
//set to FALSE to prohibit caching of video files.
define('XMOOV_CONF_ALLOW_FILE_CACHE', FALSE);
//------------------------------------------------------------------------------------------
// BANDWIDTH SETTINGS
//
// these settings are only needed when using bandwidth limiting.
//
// bandwidth is limited my sending a limited amount of video data(XMOOV_BW_PACKET_SIZE),
// in specified time intervals(XMOOV_BW_PACKET_INTERVAL).
// avoid time intervals over 1.5 seconds for best results.
//
// you can also control bandwidth limiting via http command using your video player.
// the function getBandwidthLimit($part) holds three preconfigured presets(low, mid, high),
// which can be changed to meet your needs
//------------------------------------------------------------------------------------------
//set how many kilobytes will be sent per time interval
define('XMOOV_BW_PACKET_SIZE', 90);
//set the time interval in which data packets will be sent in seconds.
define('XMOOV_BW_PACKET_INTERVAL', 0.3);
//set to TRUE to control bandwidth externally via http.
define('XMOOV_CONF_ALLOW_DYNAMIC_BANDWIDTH', TRUE);
//------------------------------------------------------------------------------------------
// DYNAMIC BANDWIDTH CONTROL
//------------------------------------------------------------------------------------------
function getBandwidthLimit($part)
{
switch($part)
{
case 'interval' :
switch($_GET[XMOOV_GET_BANDWIDTH])
{
case 'low' :
return 0.5;
break;
case 'mid' :
return 0.5;
break;
case 'high' :
return 0.2;
break;
case 'off' :
return 0;
break;
default :
return XMOOV_BW_PACKET_INTERVAL;
break;
}
break;
case 'size' :
switch($_GET[XMOOV_GET_BANDWIDTH])
{
case 'low' :
return 20;
break;
case 'mid' :
return 40;
break;
case 'high' :
return 90;
break;
default :
return XMOOV_BW_PACKET_SIZE;
break;
}
break;
}
}
//------------------------------------------------------------------------------------------
// INCOMING GET VARIABLES CONFIGURATION
//
// use these settings to configure how video files, seek position and bandwidth settings are accessed by your player
//------------------------------------------------------------------------------------------
define('XMOOV_GET_FILE', 'file');
define('XMOOV_GET_POSITION', 'start');
define('XMOOV_GET_AUTHENTICATION', 'key');
define('XMOOV_GET_BANDWIDTH', 'bw');
// END SCRIPT CONFIGURATION - do not change anything beyond this point if you do not know what you are doing
//------------------------------------------------------------------------------------------
// PROCESS FILE REQUEST
//------------------------------------------------------------------------------------------
if(isset($_GET[XMOOV_GET_FILE]) && isset($_GET[XMOOV_GET_POSITION]))
{
// PROCESS VARIABLES
# get seek position
$seekPos = intval($_GET[XMOOV_GET_POSITION]);
# get file name
$fileName = htmlspecialchars($_GET[XMOOV_GET_FILE]);
# assemble file path
$file = XMOOV_PATH_ROOT . XMOOV_PATH_FILES . $fileName;
# assemble packet interval
$packet_interval = (XMOOV_CONF_ALLOW_DYNAMIC_BANDWIDTH && isset($_GET[XMOOV_GET_BANDWIDTH])) ? getBandwidthLimit('interval') : XMOOV_BW_PACKET_INTERVAL;
# assemble packet size
$packet_size = ((XMOOV_CONF_ALLOW_DYNAMIC_BANDWIDTH && isset($_GET[XMOOV_GET_BANDWIDTH])) ? getBandwidthLimit('size') : XMOOV_BW_PACKET_SIZE) * 1042;
# security improved by by TRUI www.trui.net
if (!file_exists($file))
{
print('<b>ERROR:</b> xmoov-php could not find (' . $fileName . ') please check your settings.');
exit();
}
if(file_exists($file) && strrchr($fileName, '.') == '.flv' && strlen($fileName) > 2 && !eregi(basename($_SERVER['PHP_SELF']), $fileName) && ereg('^[^./][^/]*$', $fileName))
{
$fh = fopen($file, 'rb') or die ('<b>ERROR:</b> xmoov-php could not open (' . $fileName . ')');
$fileSize = filesize($file) - (($seekPos > 0) ? $seekPos + 1 : 0);
// SEND HEADERS
if(!XMOOV_CONF_ALLOW_FILE_CACHE)
{
# prohibit caching (different methods for different clients)
session_cache_limiter("nocache");
header("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
}
# content headers
header("Content-Type: video/x-flv");
header("Content-Disposition: attachment; filename=\"" . $fileName . "\"");
header("Content-Length: " . $fileSize);
# FLV file format header
if($seekPos != 0)
{
print('FLV');
print(pack('C', 1));
print(pack('C', 1));
print(pack('N', 9));
print(pack('N', 9));
}
# seek to requested file position
fseek($fh, $seekPos);
# output file
while(!feof($fh))
{
# use bandwidth limiting - by Terry
if(XMOOV_CONF_LIMIT_BANDWIDTH && $packet_interval > 0)
{
# get start time
list($usec, $sec) = explode(' ', microtime());
$time_start = ((float)$usec + (float)$sec);
# output packet
print(fread($fh, $packet_size));
# get end time
list($usec, $sec) = explode(' ', microtime());
$time_stop = ((float)$usec + (float)$sec);
# wait if output is slower than $packet_interval
$time_difference = $time_stop - $time_start;
if($time_difference < (float)$packet_interval)
{
usleep((float)$packet_interval * 1000000 - (float)$time_difference * 1000000);
}
}
else
{
# output file without bandwidth limiting
print(fread($fh, filesize($file)));
}
}
}
}
?>
May. 07, 2009rick
Yeah, as long as your playlist has the correct url and you use the streamer (either global or in each track if it varies), you can use the xmoov script.
This should be blank:
define('XMOOV_PATH_ROOT', '');
If you look at how the $file variable is assembled:
# assemble file path
$file = XMOOV_PATH_ROOT . XMOOV_PATH_FILES . $fileName;
Yours would be:
././video/20082009/$fileName
May. 07, 2009Chadwill
././video/20082009/$fileName
Dunno if i understood this correct tho..
but what if my file resides in ./video/anotherfolder/
and want to get the playlist of that folder with:
http://www.mydomain.com/playlist.php?dir=http://www.mydomain.com/video/anotherfolder/
will that work aswell? since the xmoov seems to have a absolut path..
May. 07, 2009Chadwill
..oh wai...
I wanted to make some links beneth the player, to change playlists..(or folders)
like:
If link on the player page is clicked,
i want to get the playlist for the path ./videos/2/
If other link is clicked,
i want to get the playlist for the path ./videos/1/
calling this in a link on the page
http://www.mydomain.com/playlist.php?dir=http://www.mydomain.com/video/anotherfolder/
will of course just display the playlist in xml, and not change the current playlist
May. 07, 2009rick
Don't get webserver paths starting from docroot confused with the local filesystem paths on the server.
The script uses the local filesystem paths.
So if the script resides in video
Your XMOOV_PATH_FILES is:
define('XMOOV_PATH_FILES', './');
Then call the files with:
streamer=http://mysite.com/xmoov.php
And setup the playlist generator to create URLs from video, like this:
<location>2/videofile.flv</location>
<location>3/videofile.flv</location>
Then the player will make a request that looks like this:
http://mysite.com/xmoov.php?start=123456&file=2/videofile.flv
And the xmoov script will look for:which is video (the current directory) plus 2/videofile.flv or video/2/videofile.flv.
./2/videofile.flv
May. 07, 2009Chadwill
Ok.. somthing must be off here..
ill post my stuff;
/default.html <-- player script
/player.swf
/swfobject.js
/playlist.php
/xmoov.php
/test/sience/sience1.flv
/test/sience/sience2.flv
/test/math/math1.flv
/test/math/math2.flv
playlist php:
<?php
// This script reads an external directory, filters the mp3/jpg/flv files and builds a playlist.
// call with: http://www.mydomain.com/path/php_read_external_directory_playlist.php?dir=http://www.externaldomain.com/path/
// search for jpg files. set this to '.flv' or '.mp3' and so on, for the other file types
$filter = '.flv';
$pattern = '#' . $filter . '#';
// path to the external directory you want to scan
$directoryurl = (isset($_GET['dir'])) ? strval($_GET['dir']) : 'http://www.externaldomain.com/path/';
// media file URL
$mediaurl = (isset($_GET['dir'])) ? strval($_GET['dir']) : 'http://www.externaldomain.com/path/';
// info URL
$infourl = '';
/////////////////////////////////// - End of Configuration - \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// get directory listing
if($directoryarray = file($directoryurl))
{
foreach($directoryarray as $file)
{
preg_match("#<a href=\"(.*?)\">#", $file, $match);
$ps = strpos(strtolower($match[1]), $filter);
if (!($ps === false))
{
$items[] = $match[1];
}
}
}
sort($items);
// arsort($items);
// shuffle($items);
// XSPF playlist - xml header and opening tags
header("content-type:text/xml;charset=utf-8");
print <<<END
<?xml version='1.0' encoding='UTF-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>Sample PHP Generated Playlist</title>
<info>$infourl</info>
<trackList>
END;
// loop through the array and write the track elements
foreach($items as $key => $value)
{
$title = preg_replace($pattern, '', $value); // remove file extension
$title = preg_replace('#_#', ' ', $title); // change underscores to spaces
$title = preg_replace('#%20#', ' ', $title); // change %20 to spaces
$title = preg_replace('#%26#', '&', $title); // change & to &
print <<<END
<track>
<title>$title</title>
<location>$mediaurl$value</location>
<annotation>This is the description for all media files.</annotation>
<info>$infourl</info>
</track>
END;
}
// closing tags
print <<<END
</trackList>
</playlist>
END;
?>
xmoov.php:
<?
/*
xmoov-php 0.9
Development version 0.9.3 beta
by: Eric Lorenzo Benjamin jr. webmaster (AT) xmoov (DOT) com
originally inspired by Stefan Richter at flashcomguru.com
bandwidth limiting by Terry streamingflvcom (AT) dedicatedmanagers (DOT) com
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License.
For more information, visit http://creativecommons.org/licenses/by-nc-sa/3.0/
For the full license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/legalcode
or send a letter to Creative Commons, 543 Howard Street, 5th Floor, San Francisco, California, 94105, USA.
*/
// SCRIPT CONFIGURATION
//------------------------------------------------------------------------------------------
// MEDIA PATH
//
// you can configure these settings to point to video files outside the public html folder.
//------------------------------------------------------------------------------------------
// points to server root
define('XMOOV_PATH_ROOT', '');
// points to the folder containing the video files.
define('XMOOV_PATH_FILES', './test/');
//------------------------------------------------------------------------------------------
// SCRIPT BEHAVIOR
//------------------------------------------------------------------------------------------
//set to TRUE to use bandwidth limiting.
define('XMOOV_CONF_LIMIT_BANDWIDTH', TRUE);
//set to FALSE to prohibit caching of video files.
// define('XMOOV_CONF_ALLOW_FILE_CACHE', FALSE);
//------------------------------------------------------------------------------------------
// BANDWIDTH SETTINGS
//
// these settings are only needed when using bandwidth limiting.
//
// bandwidth is limited my sending a limited amount of video data(XMOOV_BW_PACKET_SIZE),
// in specified time intervals(XMOOV_BW_PACKET_INTERVAL).
// avoid time intervals over 1.5 seconds for best results.
//
// you can also control bandwidth limiting via http command using your video player.
// the function getBandwidthLimit($part) holds three preconfigured presets(low, mid, high),
// which can be changed to meet your needs
//------------------------------------------------------------------------------------------
//set how many kilobytes will be sent per time interval
define('XMOOV_BW_PACKET_SIZE', 90);
//set the time interval in which data packets will be sent in seconds.
define('XMOOV_BW_PACKET_INTERVAL', 0.3);
//set to TRUE to control bandwidth externally via http.
define('XMOOV_CONF_ALLOW_DYNAMIC_BANDWIDTH', TRUE);
//------------------------------------------------------------------------------------------
// DYNAMIC BANDWIDTH CONTROL
//------------------------------------------------------------------------------------------
function getBandwidthLimit($part)
{
switch($part)
{
case 'interval' :
switch($_GET[XMOOV_GET_BANDWIDTH])
{
case 'low' :
return 0.5;
break;
case 'mid' :
return 0.5;
break;
case 'high' :
return 0.2;
break;
case 'off' :
return 0;
break;
default :
return XMOOV_BW_PACKET_INTERVAL;
break;
}
break;
case 'size' :
switch($_GET[XMOOV_GET_BANDWIDTH])
{
case 'low' :
return 20;
break;
case 'mid' :
return 40;
break;
case 'high' :
return 90;
break;
default :
return XMOOV_BW_PACKET_SIZE;
break;
}
break;
}
}
//------------------------------------------------------------------------------------------
// INCOMING GET VARIABLES CONFIGURATION
//
// use these settings to configure how video files, seek position and bandwidth settings are accessed by your player
//------------------------------------------------------------------------------------------
define('XMOOV_GET_FILE', 'file');
define('XMOOV_GET_POSITION', 'start');
define('XMOOV_GET_AUTHENTICATION', 'key');
define('XMOOV_GET_BANDWIDTH', 'bw');
// END SCRIPT CONFIGURATION - do not change anything beyond this point if you do not know what you are doing
//------------------------------------------------------------------------------------------
// PROCESS FILE REQUEST
//------------------------------------------------------------------------------------------
if(isset($_GET[XMOOV_GET_FILE]) && isset($_GET[XMOOV_GET_POSITION]))
{
// PROCESS VARIABLES
# get seek position
$seekPos = intval($_GET[XMOOV_GET_POSITION]);
# get file name
$fileName = htmlspecialchars($_GET[XMOOV_GET_FILE]);
# assemble file path
$file = XMOOV_PATH_ROOT . XMOOV_PATH_FILES . $fileName;
#
# $file = isset($_GET['dir'])) ? strval($_GET['dir']) : 'http://www.externaldomain.com/path/';
#
# assemble packet interval
$packet_interval = (XMOOV_CONF_ALLOW_DYNAMIC_BANDWIDTH && isset($_GET[XMOOV_GET_BANDWIDTH])) ? getBandwidthLimit('interval') : XMOOV_BW_PACKET_INTERVAL;
# assemble packet size
$packet_size = ((XMOOV_CONF_ALLOW_DYNAMIC_BANDWIDTH && isset($_GET[XMOOV_GET_BANDWIDTH])) ? getBandwidthLimit('size') : XMOOV_BW_PACKET_SIZE) * 1042;
# security improved by by TRUI www.trui.net
if (!file_exists($file))
{
print('<b>ERROR:</b> xmoov-php could not find (' . $fileName . ') please check your settings.');
exit();
}
if(file_exists($file) && strrchr($fileName, '.') == '.flv' && strlen($fileName) > 2 && !eregi(basename($_SERVER['PHP_SELF']), $fileName) && ereg('^[^./][^/]*$', $fileName))
{
$fh = fopen($file, 'rb') or die ('<b>ERROR:</b> xmoov-php could not open (' . $fileName . ')');
$fileSize = filesize($file) - (($seekPos > 0) ? $seekPos + 1 : 0);
// SEND HEADERS
if(!XMOOV_CONF_ALLOW_FILE_CACHE)
{
# prohibit caching (different methods for different clients)
session_cache_limiter("nocache");
header("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
}
# content headers
header("Content-Type: video/x-flv");
header("Content-Disposition: attachment; filename=\"" . $fileName . "\"");
header("Content-Length: " . $fileSize);
# FLV file format header
if($seekPos != 0)
{
print('FLV');
print(pack('C', 1));
print(pack('C', 1));
print(pack('N', 9));
print(pack('N', 9));
}
# seek to requested file position
fseek($fh, $seekPos);
# output file
while(!feof($fh))
{
# use bandwidth limiting - by Terry
if(XMOOV_CONF_LIMIT_BANDWIDTH && $packet_interval > 0)
{
# get start time
list($usec, $sec) = explode(' ', microtime());
$time_start = ((float)$usec + (float)$sec);
# output packet
print(fread($fh, $packet_size));
# get end time
list($usec, $sec) = explode(' ', microtime());
$time_stop = ((float)$usec + (float)$sec);
# wait if output is slower than $packet_interval
$time_difference = $time_stop - $time_start;
if($time_difference < (float)$packet_interval)
{
usleep((float)$packet_interval * 1000000 - (float)$time_difference * 1000000);
}
}
else
{
# output file without bandwidth limiting
print(fread($fh, filesize($file)));
}
}
}
}
?>
player:
<script type="text/javascript" src="swfobject.js"></script>
<script type='text/javascript'>
var s1 = new SWFObject('player.swf','player','900','480','9');
s1.addParam('allowfullscreen','true');
s1.addParam('allowscriptaccess','always');
s1.addParam('flashvars','file=playlist.php&streamer=http://mysite.com/xmoov.php&playlist=right&playlistsize=260&thumbsinplaylist=false&fullscreen=true&backcolor=ffffff&frontcolor=000000');
s1.write('1');
</script>
if i change flashvars','file=playlist.php to flashvars','file=playlist.php?dir=http://mysite.com/test/sience/
i get a: "couldnt find http://mysite.com/test/sience/sience1.flv"
but playlist shows up correct.
i guess xmoov.php dosent find the file at that path.
changing flashvars to: file=playlist.php?dir=/test/sience/ or dir=sience/ etc..
gives me a error:
Warning: file(/test/math/) [function.file]: failed to open stream: No such file or directory in /home3/myuser/public_html/playlist.php on line 23
Warning: sort() expects parameter 1 to be array, null given in /home3/myuser/public_html/playlist.php on line 36
Warning: Cannot modify header information - headers already sent by (output started at /home3/myuser/public_html/playlist.php:23) in /home3/myuser/public_html/playlist.php on line 41
Warning: Invalid argument supplied for foreach() in /home3/myuser/public_html/playlist.php on line 53
seems the playlist will only work with http type url
May. 08, 2009Chadwill
hm, did i mention i had a *nix server?
do i need "filemtime" somwhere maybe?
May. 08, 2009rick
The three pieces of software:
1) the player embedding code,
2) the xmoov script,
3) and the playlist generator,
are separate, independent programs. You should get each of them tested and working independently before you try to integrate them.
Each program must function independently when called from your browser:
1) the player code with a test file, (http://www.domain.com/default.html)
2) the xmoov script with a test URL, (http://www.domain.com/xmoov.php?start=123456&file=test/sience/sience1.flv)
3) the playlist generator script with a test directory. (http://www.domain.com/playlist.php?dir=test/sience)
The playlist generator script that you are using is intended for use with an external domain (the files are on a domain that is different than the domain that the script resides on). For files that are on the same domain, you need to use a slightly different script.
Also, if you want to sort the files by mtime (last modified time), there is different code for Windows based servers and *nix based servers. If you don't want to sort by mtime, that code can be removed from the playlist generator script.
Here is the playlist generator code:Test it by entering this URI in your browser: http://www.domain.com/playlist.php?dir=test/sience (Adjust the domain to yours.)
<?php
// this script reads a directory, filters the mp3/jpg/flv files and builds a playlist
// call with: http://www.domain.com/path/playlist.php?dir=directory
// search for flv files. set this to '.jpg' or '.mp3' and so on, for the other file types
$filter = '.flv';
$pattern = '#' . $filter . '#';
// path to the directory you want to scan
$directory = isset($_GET['dir']) ? strval($_GET['dir']) : 'test/sience';
// info URL
$infourl = 'http://www.domain.com/';
///////////////////////////// - End of Configuration - \\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// get directory listing
@$directoryhandle = dir($directory);
if ($directoryhandle)
{
while($entry = $directoryhandle->read())
{
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false))
{
$items[] = $entry;
}
}
}
$directoryhandle->close();
//print_r($items); exit;
sort($items);
// XSPF playlist - xml header and opening tags
header("content-type:text/xml;charset=utf-8");
print <<<END
<?xml version='1.0' encoding='UTF-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>Sample PHP Generated Playlist</title>
<info>$infourl</info>
<trackList>
END;
// loop through the array and write the track elements
foreach($items as $value)
{
$title = preg_replace($pattern, '', $value); // remove file extension
$title = preg_replace('#_#', ' ', $title); // change underscores to spaces
$title = preg_replace('#%20#', ' ', $title); // change %20 to spaces
$title = preg_replace('#%26#', '&', $title); // change %26 to &
print <<<END
<track>
<title>$title</title>
<location>$directory/$value</location>
<image>$directory/$title.jpg</image>
<annotation>This is the description for all media files.</annotation>
<info>$infourl</info>
</track>
END;
}
// closing tags
print <<<END
</trackList>
</playlist>
END;
?>
The playlist.php script should return a playlist that looks like this:
<?xml version='1.0' encoding='UTF-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>Sample PHP Generated Playlist</title>
<info>http://www.domain.com/</info>
<trackList>
<track>
<title>TheVideoTitle</title>
<location>test/sience/TheVideoTitle.flv</location>
<image>test/sience/TheVideoTitle.jpg</image>
<annotation>This is the description for all media files.</annotation>
<info>http://www.domain.com/</info>
</track>
</trackList>
</playlist>
May. 08, 2009Chadwill
you sir.... just rock!
works nicely rick
.. now i just have to figure out how to call and change playlist.php variable in a link, while loading my player page :P
EDIT: I just love this community, lot of great people here, i gotta say
May. 08, 2009rick
See this post for an example of using query parameters.
http://www.longtailvideo.com/support/forum/Setup-Problems/16587/Opening-links#msg112477
Once you have your query parameter as a JS variable, say as the JS variable named dir, slip it in to your flashvars like this:
s1.addParam('flashvars','file=playlist.php?dir=' + dir + '&streamer=...
May. 08, 2009Chadwill
<script type="text/javascript" src="swfobject.js">
var dir = true;
if(!(dir = swfobject.getQueryParamValue('dir')))
{
dir = 'http://mysite.com';
};
</script>
guess im pretty far out.. hehe
Have tried to implement this a lot of way(mostly trial and error) gotten this a lot tho: dir is undefined
May. 08, 2009Chadwill
Ok managed to solve it with:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>ORME FAGSKOLE</title>
<script type="text/javascript" src="swfobject.js"></script>
<script type='text/javascript'>
var dir = location.search.match(/[\?&]dir=(.*?)(&|$)/); dir = dir && dir[1];
</script>
</head>
<body>
<p id='1'>The player will show in this paragraph</p>
<script type='text/javascript'>
var s1 = new SWFObject('player.swf','player','900','480','9');
s1.addParam('allowfullscreen','true');
s1.addParam('allowscriptaccess','always');
s1.addParam('flashvars','file=play.php?dir=' + dir + '&http://mysite.com/xmoov.php&playlist=right&playlistsize=260&thumbsinplaylist=false&fullscreen=true&backcolor=ffffff&frontcolor=000000');
s1.write('1');
</script>
</body>
</html>
May. 08, 2009Chadwill
correction to last post:
s1.addParam('flashvars','file=play.php?dir=' + dir + '&streamer=http://mysite.com/xmoov.php
Damn.. still somthing fishy here..
without xmoov.php:
videos play
playlist is displayed right
generated xml looks good
links work: http://mysite.com/?dir=test/sience
but i am unable to scrub(skip) the videos..
when i add xmoov.php.. it looks like the player is loading forever, spinning circle.. and no video or errors
May. 08, 2009rick
It should be:because you want to test if (dir = swfobject.getQueryParamValue('dir')) returns true, thus indicating that the query parameter dir has some value.
<script type="text/javascript">
var dir = null;
if(!(dir = swfobject.getQueryParamValue('dir')))
{
//...default directory
dir = 'http://mysite.com';
};
Also, you should urlencode the two special characters in the file URL, like this:
s1.addParam('flashvars','file=play.php%3Fdir%3D' + dir + '&streamer=http://mysite.com/xmoov.php...
Does the xmoov script work when you test it with your browser? Use varying start byte positions and you should get varying file sizes that download in your browser.
You can add some debug code to the xmoov script so when you call it in your browser, you can see if the $file variable has the correct value:Add the line in bold underneath the two lines of existing code.
# assemble file path
$file = XMOOV_PATH_ROOT . XMOOV_PATH_FILES . $fileName;
print $file; exit;
Have you added the metadata array to your FLV files with one of the available post-processing tools like FLVMDI, flvtool++, or flvtool2?
May. 09, 2009Chadwill
dont have the time to test atm.. but yes the xmoov script works great when using singel files
May. 11, 2009Chadwill
hm..i must be doing it wrong again.. with this code im getting either swfobject not defined.. or dir is not defined..
May. 11, 2009rick
These are separate issues.
You will only get "swfobject not defined" if swfobject.js is not loaded or if it is the wrong version.
The JavaScript variable dir is defined here:var dir = null;
The only way you could be getting "dir is not defined" is if that line of code is missing.
May. 12, 2009Chadwill
well those lines are there.. and all files are present
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>my site</title>
</head>
<body>
<p id='1'>Player here</p>
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
var dir = null;
if(!(dir = swfobject.getQueryParamValue('dir')))
{
//...default directory
dir = 'http://mysite.com';
};
</script>
<script language="JavaScript" type="text/javascript">
var s1 = new SWFObject('player.swf','player','900','480','9');
s1.addParam('allowfullscreen','true');
s1.addParam('allowscriptaccess','always');
s1.addParam('flashvars','file=play.php%3Fdir%3D'+ dir +'&streamer=http://mysite.com/xmoov.php&playlist=right&playlistsize=260&thumbsinplaylist=false&fullscreen=true&backcolor=ffffff&frontcolor=000000');
s1.write('1');
</script>
<p><a href="http://mysite.com/?dir=test/sience">sience</a></p>
<p><a href="http://mysite.com/?dir=test/math">math</a></p>
<p><a href="http://mysite.com/?dir=video/20082009">test</a></p>
</body>
</html>
ive tested that both xmoov and playlist scripts are working.
May. 12, 2009lollie
When you use the obsolete version of SWFObject, you also have to use the obsolete form of getQueryParamValue()
<script type="text/javascript">
var dir = null;
if(!(dir = getQueryParamValue('dir')))
{
//...default directory
dir = 'http://mysite.com';
}
</script>
May. 12, 2009Chadwill
oh gawd.. what the h*** am i doing wrong..
changed it acording to lollie it works both ways withouth the streamer line tho..
xmoov works for itself..
playlist is generated correctly
everything seems peachy until i add the xmoov.
and i call the site with mysite.com?dir=test/sience
summary:
xmoov.php works with my flv's independly
playlist works great without xmoov.php
<p id='1'>The player will show in this paragraph</p>
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
var dir = null;
if(!(dir = getQueryParamValue('dir')))
{
//...default directory
dir = 'test/sience';
};
</script>
<script language="JavaScript" type="text/javascript">
var s1 = new SWFObject('player.swf','player','900','480','9');
s1.addParam('allowfullscreen','true');
s1.addParam('allowscriptaccess','always');
s1.addParam('flashvars','file=play.php%3Fdir%3D'+ dir +'&streamer=http://mysite.com/xmoov.php&playlist=right&playlistsize=260&thumbsinplaylist=false&fullscreen=true&backcolor=ffffff&frontcolor=000000');
s1.write('1');
</script>
<?php
// this script reads a directory, filters the mp3/jpg/flv files and builds a playlist
// call with: http://www.domain.com/path/playlist.php?dir=directory
// search for flv files. set this to '.jpg' or '.mp3' and so on, for the other file types
$filter = '.flv';
$pattern = '#' . $filter . '#';
// path to the directory you want to scan
$directory = isset($_GET['dir']) ? strval($_GET['dir']) : 'test/sience';
// info URL
$infourl = 'http://www.domain.com/';
///////////////////////////// - End of Configuration - \\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// get directory listing
@$directoryhandle = dir($directory);
if ($directoryhandle)
{
while($entry = $directoryhandle->read())
{
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false))
{
$items[] = $entry;
}
}
}
$directoryhandle->close();
//print_r($items); exit;
sort($items);
// XSPF playlist - xml header and opening tags
header("content-type:text/xml;charset=utf-8");
print <<<END
<?xml version='1.0' encoding='UTF-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>Sample PHP Generated Playlist</title>
<info>$infourl</info>
<trackList>
END;
// loop through the array and write the track elements
foreach($items as $value)
{
$title = preg_replace($pattern, '', $value); // remove file extension
$title = preg_replace('#_#', ' ', $title); // change underscores to spaces
$title = preg_replace('#%20#', ' ', $title); // change %20 to spaces
$title = preg_replace('#%26#', '&', $title); // change %26 to &
print <<<END
<track>
<title>$title</title>
<location>$directory/$value</location>
<image></image>
<annotation></annotation>
<info></info>
</track>
END;
}
// closing tags
print <<<END
</trackList>
</playlist>
END;
?>
May. 12, 2009lollie
Do you still have this code in xmoov.php?
// points to server root
define('XMOOV_PATH_ROOT', '');
// points to the folder containing the video files.
define('XMOOV_PATH_FILES', './test/');
It should look like this, because you already have the test directory in your playlist track location element.
// points to server root
define('XMOOV_PATH_ROOT', '');
// points to the folder containing the video files.
define('XMOOV_PATH_FILES', './');
<location>test/sience/TheVideoTitle.flv</location>
Then your streamer and file requests should look like this:
streamer=http://mysite.com/xmoov.php?file=test/sience/TheVideoTitle.flv&start=123456
file=http://mysite.com/play.php?dir=test/sience
You can check the assembled $file variable in the xmoov script by placing the line of code in bold in the xmoov script after the first two lines:then call xmoov.php from your browser with:
# assemble file path
$file = XMOOV_PATH_ROOT . XMOOV_PATH_FILES . $fileName;
print $file; exit;
http://mysite.com/xmoov.php?file=test/sience/TheVideoTitle.flv&start=123456
It should return this to your browser:
./test/sience/TheVideoTitle.flv
Current player embedding code should be:
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
var dir = null;
if(!(dir = getQueryParamValue('dir')))
{
//...default directory
dir = 'test/sience';
}
</script>
<script language="JavaScript" type="text/javascript">
alert('Dir: ' + dir);
var s1 = new SWFObject('player.swf', 'player', '900', '480', '9.0.124');
s1.addParam('allowfullscreen', 'true');
s1.addParam('allowscriptaccess', 'always');
s1.addVariable('file', encodeURIComponent('play.php?dir=' + dir));
s1.addVariable('streamer', 'http://mysite.com/xmoov.php');
s1.addVariable('playlist', 'right');
s1.addVariable('playlistsize' '260');
s1.addVariable('backcolor', 'FFFFFF')
s1.addVariable('frontcolor', '000000');
s1.write('1');
</script>
May. 12, 2009lollie
If this doesn't work, let's make a fresh start.
You post (copy & paste from your server):
1) play.php,
2) xmoov.php,
3) full player embedding code,
4) a few tracks of the playlist generated by play.php,
5) your current directory structure.
May. 13, 2009Chadwill
still having the "spinning/loading player"
http://mysite.com/xmoov.php?file=test/sience/sience1.flv&start=123456 -->
./test/sience/sience1.flv
http://mysite.com/play.php?dir=test/sience -->
- <playlist version="1" xmlns="http://xspf.org/ns/0/">
<title>Sample PHP Generated Playlist</title>
<info>http://www.domain.com/</info>
- <trackList>
- <track>
<title>sience1</title>
<location>test/sience/sience1.flv</location>
<image />
<annotation />
<info />
</track>
- <track>
might aswell post the rest:
play.php :
<?php
// this script reads a directory, filters the mp3/jpg/flv files and builds a playlist
// call with: http://www.domain.com/path/playlist.php?dir=directory
// search for flv files. set this to '.jpg' or '.mp3' and so on, for the other file types
$filter = '.flv';
$pattern = '#' . $filter . '#';
// path to the directory you want to scan
$directory = isset($_GET['dir']) ? strval($_GET['dir']) : 'test/sience';
// info URL
$infourl = 'http://www.domain.com/';
///////////////////////////// - End of Configuration - \\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// get directory listing
@$directoryhandle = dir($directory);
if ($directoryhandle)
{
while($entry = $directoryhandle->read())
{
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false))
{
$items[] = $entry;
}
}
}
$directoryhandle->close();
//print_r($items); exit;
sort($items);
// XSPF playlist - xml header and opening tags
header("content-type:text/xml;charset=utf-8");
print <<<END
<?xml version='1.0' encoding='UTF-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>Sample PHP Generated Playlist</title>
<info>$infourl</info>
<trackList>
END;
// loop through the array and write the track elements
foreach($items as $value)
{
$title = preg_replace($pattern, '', $value); // remove file extension
$title = preg_replace('#_#', ' ', $title); // change underscores to spaces
$title = preg_replace('#%20#', ' ', $title); // change %20 to spaces
$title = preg_replace('#%26#', '&', $title); // change %26 to &
print <<<END
<track>
<title>$title</title>
<location>$directory/$value</location>
<image></image>
<annotation></annotation>
<info></info>
</track>
END;
}
// closing tags
print <<<END
</trackList>
</playlist>
END;
?>
xmoov.php :
// points to server root
define('XMOOV_PATH_ROOT', '');
// points to the folder containing the video files.
define('XMOOV_PATH_FILES', './');
//------------------------------------------------------------------------------------------
// SCRIPT BEHAVIOR
//------------------------------------------------------------------------------------------
//set to TRUE to use bandwidth limiting.
define('XMOOV_CONF_LIMIT_BANDWIDTH', TRUE);
//set to FALSE to prohibit caching of video files.
define('XMOOV_CONF_ALLOW_FILE_CACHE', FALSE);
//------------------------------------------------------------------------------------------
// BANDWIDTH SETTINGS
//
// these settings are only needed when using bandwidth limiting.
//
// bandwidth is limited my sending a limited amount of video data(XMOOV_BW_PACKET_SIZE),
// in specified time intervals(XMOOV_BW_PACKET_INTERVAL).
// avoid time intervals over 1.5 seconds for best results.
//
// you can also control bandwidth limiting via http command using your video player.
// the function getBandwidthLimit($part) holds three preconfigured presets(low, mid, high),
// which can be changed to meet your needs
//------------------------------------------------------------------------------------------
//set how many kilobytes will be sent per time interval
define('XMOOV_BW_PACKET_SIZE', 90);
//set the time interval in which data packets will be sent in seconds.
define('XMOOV_BW_PACKET_INTERVAL', 0.3);
//set to TRUE to control bandwidth externally via http.
define('XMOOV_CONF_ALLOW_DYNAMIC_BANDWIDTH', TRUE);
//------------------------------------------------------------------------------------------
// DYNAMIC BANDWIDTH CONTROL
//------------------------------------------------------------------------------------------
function getBandwidthLimit($part)
{
switch($part)
{
case 'interval' :
switch($_GET[XMOOV_GET_BANDWIDTH])
{
case 'low' :
return 0.5;
break;
case 'mid' :
return 0.5;
break;
case 'high' :
return 0.2;
break;
case 'off' :
return 0;
break;
default :
return XMOOV_BW_PACKET_INTERVAL;
break;
}
break;
case 'size' :
switch($_GET[XMOOV_GET_BANDWIDTH])
{
case 'low' :
return 20;
break;
case 'mid' :
return 40;
break;
case 'high' :
return 90;
break;
default :
return XMOOV_BW_PACKET_SIZE;
break;
}
break;
}
}
//------------------------------------------------------------------------------------------
// INCOMING GET VARIABLES CONFIGURATION
//
// use these settings to configure how video files, seek position and bandwidth settings are accessed by your player
//------------------------------------------------------------------------------------------
define('XMOOV_GET_FILE', 'file');
define('XMOOV_GET_POSITION', 'start');
define('XMOOV_GET_AUTHENTICATION', 'key');
define('XMOOV_GET_BANDWIDTH', 'bw');
// END SCRIPT CONFIGURATION - do not change anything beyond this point if you do not know what you are doing
//------------------------------------------------------------------------------------------
// PROCESS FILE REQUEST
//------------------------------------------------------------------------------------------
if(isset($_GET[XMOOV_GET_FILE]) && isset($_GET[XMOOV_GET_POSITION]))
{
// PROCESS VARIABLES
# get seek position
$seekPos = intval($_GET[XMOOV_GET_POSITION]);
# get file name
$fileName = htmlspecialchars($_GET[XMOOV_GET_FILE]);
# assemble file path
$file = XMOOV_PATH_ROOT . XMOOV_PATH_FILES . $fileName;
#
print $file; exit;
# assemble packet interval
$packet_interval = (XMOOV_CONF_ALLOW_DYNAMIC_BANDWIDTH && isset($_GET[XMOOV_GET_BANDWIDTH])) ? getBandwidthLimit('interval') : XMOOV_BW_PACKET_INTERVAL;
# assemble packet size
$packet_size = ((XMOOV_CONF_ALLOW_DYNAMIC_BANDWIDTH && isset($_GET[XMOOV_GET_BANDWIDTH])) ? getBandwidthLimit('size') : XMOOV_BW_PACKET_SIZE) * 1042;
# security improved by by TRUI www.trui.net
if (!file_exists($file))
{
print('<b>ERROR:</b> xmoov-php could not find (' . $fileName . ') please check your settings.');
exit();
}
if(file_exists($file) && strrchr($fileName, '.') == '.flv' && strlen($fileName) > 2 && !eregi(basename($_SERVER['PHP_SELF']), $fileName) && ereg('^[^./][^/]*$', $fileName))
{
$fh = fopen($file, 'rb') or die ('<b>ERROR:</b> xmoov-php could not open (' . $fileName . ')');
$fileSize = filesize($file) - (($seekPos > 0) ? $seekPos + 1 : 0);
// SEND HEADERS
if(!XMOOV_CONF_ALLOW_FILE_CACHE)
{
# prohibit caching (different methods for different clients)
session_cache_limiter("nocache");
header("Expires: Thu, 19 Nov 1981 08:52:00 GMT");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
header("Pragma: no-cache");
}
# content headers
header("Content-Type: video/x-flv");
header("Content-Disposition: attachment; filename=\"" . $fileName . "\"");
header("Content-Length: " . $fileSize);
# FLV file format header
if($seekPos != 0)
{
print('FLV');
print(pack('C', 1));
print(pack('C', 1));
print(pack('N', 9));
print(pack('N', 9));
}
# seek to requested file position
fseek($fh, $seekPos);
# output file
while(!feof($fh))
{
# use bandwidth limiting - by Terry
if(XMOOV_CONF_LIMIT_BANDWIDTH && $packet_interval > 0)
{
# get start time
list($usec, $sec) = explode(' ', microtime());
$time_start = ((float)$usec + (float)$sec);
# output packet
print(fread($fh, $packet_size));
# get end time
list($usec, $sec) = explode(' ', microtime());
$time_stop = ((float)$usec + (float)$sec);
# wait if output is slower than $packet_interval
$time_difference = $time_stop - $time_start;
if($time_difference < (float)$packet_interval)
{
usleep((float)$packet_interval * 1000000 - (float)$time_difference * 1000000);
}
}
else
{
# output file without bandwidth limiting
print(fread($fh, filesize($file)));
}
}
}
}
?>
player :
<p id='1'>The player will show in this paragraph</p>
<script type="text/javascript" src="swfobject.js"></script>
<script type="text/javascript">
var dir = null;
if(!(dir = getQueryParamValue('dir')))
{
//...default directory
dir = 'test/sience';
}
</script>
<script language="JavaScript" type="text/javascript">
alert('Dir: ' + dir);
var s1 = new SWFObject('player.swf', 'player', '900', '480', '9');
s1.addParam('allowfullscreen', 'true');
s1.addParam('allowscriptaccess', 'always');
s1.addVariable('streamer', 'http://mysite.com/xmoov.php');
s1.addVariable('file', encodeURIComponent('play.php?dir=' + dir));
s1.addVariable('playlist', 'right');
s1.addVariable('playlistsize', '260');
s1.addVariable('backcolor', 'FFFFFF');
s1.addVariable('frontcolor', '000000');
s1.write('1');
</script>
dir:
/xmoov.php
/play.php
/default.html <-- embedding code
/swfobject.js
/player.swf
/test/sience/sience1.flv
................./sience2.flv
/test/math/math1.flv
.............../math2.flv
May. 13, 2009lollie
Everything looks OK...
What happens if you call the xmoov.php script with your browser using various byte positions? Are you able to download files of varying sizes?
http://mysite.com/xmoov.php?file=test/sience/sience1.flv&start=123456
http://mysite.com/xmoov.php?file=test/sience/sience1.flv&start=234567
http://mysite.com/xmoov.php?file=test/sience/sience1.flv&start=345678
One other way to troubleshoot this, would be to install the "Live HTTP Headers" plugin for Firefox, then see what requests the player is making to the xmoov.php script and what the server's response is.
May. 13, 2009Chadwill
http://mysite.com/xmoov.php?file=test/sience/sience1.flv&start=345678
gives still ./test/sience/sience1.flv
in the browser.
Live http headers:
GET /?dir=test/sience
GET /play.php?dir=test/sience
GET /xmoov.php?file=test/sience/sience1.flv&start=0
#request# GET http://mysite.com/xmoov.php?file=test/sience/sience1.flv&start=0
GET /xmoov.php?file=test/sience/sience1.flv&start=0
not sure if this info is any helpful at all
May. 13, 2009lollie
Before you test in your browser or with the player, comment out the debug code:so the xmoov.php script can continue on it's merry way. Then you should be able to download FLV files. (Your browser may tell you the file is named "xmoov.php", just ignore that.)
// print $file; exit;
Can you post the full server response from Live HTTP Headers? Copy & Paste the full session from the initial request through the server response headers.
May. 13, 2009Chadwill
http://mysite.com/xmoov.php?file=test/sience/sience1.flv&start=123456
http://mysite.com/xmoov.php?file=test/sience/sience1.flv&start=234567
http://mysite.com/xmoov.php?file=test/sience/sience1.flv&start=345678
Well.. i get just a blank page without the debug code.
And ive tried with IE7/IE8/Chrome/FF3
headers:
http://mysite.com/xmoov.php?file=test/sience/sience1.flv&start=345678
GET /xmoov.php?file=test/sience/sience1.flv&start=345678 HTTP/1.1
Host: mysite.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; nb-NO; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: nb,no;q=0.8,nn;q=0.6,en-us;q=0.4,en;q=0.2
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
HTTP/1.x 200 OK
Date: Wed, 13 May 2009 19:47:55 GMT
Server: Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8i DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
X-Powered-By: PHP/5.2.9
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html
----------------------------------------------------------
Generator:
#request# GET http://mysite.com/xmoov.php?file=test/sience/sience1.flv&start=345678
GET /xmoov.php?file=test/sience/sience1.flv&start=345678
when pressing play on sience1.flv in play list, it spins forever..
headers:
http://mysite.com/xmoov.php?file=test/sience/sience1.flv&start=0
GET /xmoov.php?file=test/sience/sience1.flv&start=0 HTTP/1.1
Host: mysite.com
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; nb-NO; rv:1.9.0.10) Gecko/2009042316 Firefox/3.0.10
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: nb,no;q=0.8,nn;q=0.6,en-us;q=0.4,en;q=0.2
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
HTTP/1.x 200 OK
Date: Wed, 13 May 2009 19:42:53 GMT
Server: Apache/2.2.11 (Unix) mod_ssl/2.2.11 OpenSSL/0.9.8i DAV/2 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
X-Powered-By: PHP/5.2.9
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/html
----------------------------------------------------------
Generator:
#request# GET http://mysite.com/xmoov.php?file=test/sience/sience1.flv&start=0
GET /xmoov.php?file=test/sience/sience1.flv&start=0
May. 13, 2009lollie
The correct request is getting to your server, but the xmoov script is not responding with the file.
Let me test your xmoov.php code to see what is wrong.
May. 14, 2009Chadwill
its a few posts up ^
May. 14, 2009lollie
The problem lies in this line of code:
if(file_exists($file) && strrchr($fileName, '.') == '.flv' && strlen($fileName) > 2 && !eregi(basename($_SERVER['PHP_SELF']), $fileName) && ereg('^[^./][^/]*$', $fileName))
In particular, this chunk, which doesn't let you use a directory separator symbol in the filename:
ereg('^[^./][^/]*$', $fileName)
You could just remove that chunk, but then there are some security problems.
The code should just prevent using the directory separator symbol (or the root directory symbol) as the first character of the filename.
I gotta think about this a bit.
Meanwhile, for testing only, you could remove that chunk of code so it works.
May. 14, 2009Chadwill
if(file_exists($file) && strrchr($fileName, '.') == '.flv' && strlen($fileName) > 2 && !eregi(basename($_SERVER['PHP_SELF']), $fileName))
with this, it still didnt work.. no errors either
May. 14, 2009lollie
Working here with your xmoov.php script with the modification: http://willswonders.myip.org:8085/php/Simple_XMOOV_Streaming.html
You can download the modified script from here: http://willswonders.myip.org:8085/php/xmoov_Chadwill.txt Re-name the script to whatever you want after you have downloaded it.
May. 14, 2009Chadwill
hm..
Is it ok if i call the script "OMFG_lollie_you_rock_my_socks.php" ??
May. 14, 2009lollie
Whatever works for you!
May. 14, 2009Chadwill
Thanks a lot lollie and rick, for taking the time and sanity to help me.
Also hope some of the post could be valuable for others aswell
Jun. 21, 2009Clayton Tschirhart
Is there a way to make a .jpg rotator playlist that show's a single jpg first everytime but then randomizes the rest of the jpg's in the folder?
Thanks for you help.
Jun. 21, 2009ringo
Unfortunately, because of timing issues, this doesn't work very well. The first random image is shown slightly before the first non-random image is shown. But I think that this is about the best that can be done, since the Image Rotator doesn't have the JavaScript Events to do anything else.
I suppose you could also try initially loading a playlist of one item, then load the multi-item playlist, but there will be an abrupt transition when the new playlist starts.
Test page; http://willswonders.myip.org:8074/Simple_RotatorTitleImage.html
Jun. 23, 2009Clayton
First of all, thank you for your help.
I was wondering if it was possible to add a specific track to the .PHP code and then have the rest of the tracks added automatically to the playlist from the folder?
Is there a value for the sort command that can make them randomized rather than ascending or descending?
Jun. 23, 2009ringo
Exactly which PHP code are you referring to?
You can place a track before the loop, then it will always be the first track.
You can sort/shufle the array any way that you want.
Once I know exactly which PHP you are using (please post it here), I can show you where to add the first track and the sorting/shuffling.
Jun. 23, 2009Clayton
<?php
/*
* This is a sample file that reads through a directory, filters the mp3/jpg/flv
* files and builds a playlist from it. After looking through this file, you'll
* probably 'get the idea' and'll be able to setup your own directory.
*
*/
// set this to a creator name
$creator = "Myself";
// search for mp3 files. set this to '.flv' or '.jpg' for the other scripts
$filter = ".jpg";
// path to the directory you want to scan
// "./" = current directory
$directory = "./";
// URL to files
$url = "http://thart.dyndns.org/claytschirhart/myspace/images";
/////////////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false))
{
$items[$entry]['mtime'] = filemtime($entry);
}
}
$d->close();
arsort($items);
}
// the playlist is built in an xspf format
// first, we'll add an xml header and the opening tags...
header("content-type:text/xml;charset=utf-8");
echo "<?xml version='1.0' encoding='utf-8'?>\n";
echo "<playlist version='1' xmlns='http://xspf.org/ns/0/'>\n";
echo " <title>Sample PHP Generated Playlist</title>\n";
echo " <info>" . $url . "</info>\n";
echo " <trackList>\n";
// ...then we loop through the array...
foreach($items as $key => $value)
{
$title = substr($key, 0, strlen($key) - 4);
echo " <track>\n";
echo " <creator>" . $creator . "</creator>\n";
echo " <title>" . $title . "</title>\n";
echo " <location>" . $url . '/' . $key . "</location>\n";
echo " <info>" . $url . "</info>\n";
echo " </track>\n";
}
// ...and last we add the closing tags
echo " </trackList>\n";
echo "</playlist>\n";
/*
* That's it! You can feed this playlist to the SWF by setting this as it's 'file'
* parameter in your HTML page.
*/
?>
I would like to add a reference to a specific jpg first (http://thart.dyndns.org/claytschirhart/myspace/welcome.jpg) then continue to automatically add the files in a folder in a random order to the playlist.
Thanks for your help,
Clayton
Jun. 24, 2009lost
<?php
//...This script reads through a directory, filters the files by type (mp3/jpg/flv) and builds an XSPF playlist.
//...set this to a creator name
$creator = 'Myself';
//...set this to the type to filter for
$filter = '.jpg';
//...set this to the directory to scan for files
//..."./" = current directory
$directory = './';
//...set this to the URL to the files (used for the location and info elements)
$url = 'http://thart.dyndns.org/claytschirhart/myspace/images';
/////////////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
//...read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false))
{
$items[] = $entry;
}
}
$d->close();
shuffle(&$items);
}
//...xml header and opening tags
header("Content-type: text/xml;charset=utf-8");
print <<<END
<?xml version='1.0' encoding='utf-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>Playlist Title</title>
<trackList>
<track>
<creator>$creator</creator>
<title>Welcome</title>
<location>http://thart.dyndns.org/claytschirhart/myspace/welcome.jpg</location>
<info>$url</info>
</track>
END;
//...loop through the array
foreach($items as $value)
{
//...chop off the extension to create the title
$title = substr($value, 0, strlen($value) - 4);
print <<<END
<track>
<creator>$creator</creator>
<title>$title</title>
<location>$url/$value</location>
<info>$url</info>
</track>
END;
}
//...closing tags
print <<<END
</trackList>
</playlist>
END;
?>
If you don't want the full URI to the images to be used for the info link, just enter the URI that you want to use here:or delete the element if you don't want an info link.
<info>http://thart.dyndns.org/</info>
Test link: http://willswonders.myip.org:8074/playlist_Clayton.php
Jun. 24, 2009Clayton
Thank you so so much!
Jun. 24, 2009lost
You're welcome — enjoy!
Good Luck!
Jul. 10, 2009Clayton
I was using a code to generate a playlist that plays a single song first and then shuffles the rest of the songs. It was working fine but then I upgraded my php server and now I'm having issues. If I change the "shuffle" function a "arsort" it i get the correct links, however, I want them shuffled. Thanks for any help in advance.
Code:
<?php
/*
* This is a sample file that reads through a directory, filters the mp3/jpg/flv
* files and builds a playlist from it. After looking through this file, you'll
* probably 'get the idea' and'll be able to setup your own directory.
*
*/
// set this to a creator name
$creator = "Myself";
// search for mp3 files. set this to '.flv' or '.jpg' for the other scripts
$filter = ".mp3";
// path to the directory you want to scan
// "./" = current directory
$directory = "./";
// URL to files
$url = "http://thart.dyndns.org/gettinclayed/myspace/media/music";
/////////////////////////// no user configuration variables below this \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false))
{
$items[$entry]['mtime'] = filemtime($entry);
}
}
$d->close();
shuffle($items);
}
// the playlist is built in an xspf format
// first, we'll add an xml header and the opening tags...
header("content-type:text/xml;charset=utf-8");
echo "<?xml version='1.0' encoding='utf-8'?>\n";
echo "<playlist version='1' xmlns='http://xspf.org/ns/0/'>\n";
echo " <title>Sample PHP Generated Playlist</title>\n";
echo " <info>" . $url . "</info>\n";
echo " <trackList>\n";
echo " <track>\n";
echo " <creator></creator>\n";
echo " <title></title>\n";
echo " <location>http://thart.dyndns.org/gettinclayed/myspace/media/music/The Black-Eyed Peas - I Gotta Feeling.mp3</location>\n";
echo " <info></info>\n";
echo " </track>\n";
// ...then we loop through the array...
foreach($items as $key => $value)
{
$title = substr($key, 0, strlen($key) - 4);
echo " <track>\n";
echo " <creator>" . $creator . "</creator>\n";
echo " <title>" . $title . "</title>\n";
echo " <location>" . $url . '/' . $key . "</location>\n";
echo " <info>" . $url . "</info>\n";
echo " </track>\n";
}
// ...and last we add the closing tags
echo " </trackList>\n";
echo "</playlist>\n";
/*
* That's it! You can feed this playlist to the SWF by setting this as it's 'file'
* parameter in your HTML page.
*/
?>
Returns:
<?xml version="1.0" encoding="utf-8" ?>
- <playlist version="1" xmlns="http://xspf.org/ns/0/">
<title>Sample PHP Generated Playlist</title>
<info>http://thart.dyndns.org/gettinclayed/myspace/media/music</info>
- <trackList>
- <track>
<creator />
<title />
<location>http://thart.dyndns.org/gettinclayed/myspace/media/music/The Black-Eyed Peas - I Gotta Feeling.mp3</location>
<info />
</track>
- <track>
<creator>Myself</creator>
<title />
<location>http://thart.dyndns.org/gettinclayed/myspace/media/music/0</location>
<info>http://thart.dyndns.org/gettinclayed/myspace/media/music</info>
</track>
- <track>
<creator>Myself</creator>
<title />
<location>http://thart.dyndns.org/gettinclayed/myspace/media/music/1</location>
<info>http://thart.dyndns.org/gettinclayed/myspace/media/music</info>
</track>
- <track>
<creator>Myself</creator>
<title />
<location>http://thart.dyndns.org/gettinclayed/myspace/media/music/2</location>
<info>http://thart.dyndns.org/gettinclayed/myspace/media/music</info>
</track>
- <track>
<creator>Myself</creator>
<title />
<location>http://thart.dyndns.org/gettinclayed/myspace/media/music/3</location>
<info>http://thart.dyndns.org/gettinclayed/myspace/media/music</info>
</track>
- <track>
<creator>Myself</creator>
<title />
<location>http://thart.dyndns.org/gettinclayed/myspace/media/music/4</location>
<info>http://thart.dyndns.org/gettinclayed/myspace/media/music</info>
</track>
- <track>
<creator>Myself</creator>
<title />
<location>http://thart.dyndns.org/gettinclayed/myspace/media/music/5</location>
<info>http://thart.dyndns.org/gettinclayed/myspace/media/music</info>
</track>
- <track>
<creator>Myself</creator>
<title />
<location>http://thart.dyndns.org/gettinclayed/myspace/media/music/6</location>
<info>http://thart.dyndns.org/gettinclayed/myspace/media/music</info>
</track>
+ <track>
<creator>Myself</creator>
<title />
<location>http://thart.dyndns.org/gettinclayed/myspace/media/music/7</location>
<info>http://thart.dyndns.org/gettinclayed/myspace/media/music</info>
</track>
- <track>
<creator>Myself</creator>
<title />
<location>http://thart.dyndns.org/gettinclayed/myspace/media/music/8</location>
<info>http://thart.dyndns.org/gettinclayed/myspace/media/music</info>
</track>
- <track>
<creator>Myself</creator>
<title />
<location>http://thart.dyndns.org/gettinclayed/myspace/media/music/9</location>
<info>http://thart.dyndns.org/gettinclayed/myspace/media/music</info>
</track>
- <track>
<creator>Myself</creator>
<title />
<location>http://thart.dyndns.org/gettinclayed/myspace/media/music/10</location>
<info>http://thart.dyndns.org/gettinclayed/myspace/media/music</info>
</track>
- <track>
<creator>Myself</creator>
<title />
<location>http://thart.dyndns.org/gettinclayed/myspace/media/music/11</location>
<info>http://thart.dyndns.org/gettinclayed/myspace/media/music</info>
</track>
</trackList>
</playlist>
Jul. 10, 2009lost
PHP's shuffle() function won't work on an associative array.
But if you're going to shuffle the items, you don't need to get the filemtime
and then use an associative array to hold it.
Use this code:
// read through the directory and filter files to an array
@$d = dir($directory);
if ($d)
{
while($entry = $d->read())
{
$ps = strpos(strtolower($entry), $filter);
if (!($ps === false))
{
$items[] = $entry;
}
}
$d->close();
shuffle($items);
}
Jul. 11, 2009Clayton
I changed out that piece of code but it was still giving me a numeric value rather than the value of the file.
Jul. 11, 2009lost
OOPS!
// ...then we loop through the array...
foreach($items as $value)
{
$title = substr($value, 0, strlen($value) - 4);
echo " <track>\n";
echo " <creator>" . $creator . "</creator>\n";
echo " <title>" . $title . "</title>\n";
echo " <location>" . $url . '/' . $value . "</location>\n";
echo " <info>" . $url . "</info>\n";
echo " </track>\n";
}
Now I'm curious. How did this ever work before???
Aug. 25, 2009Mac
Thanks AJAX!
Your little script just saved the day.. Kudos!!
Aug. 25, 2009killerRSS
I'm a runner for AJAX.
He's currently out on the beach here at Playa de Ninguna Parte, sippin' a cold Corona.
AJAX says, "You're welcome — enjoy!"
Sep. 26, 2009Ameisez
Hi Ajax,
I have this code that I found somewhere here.
<?php
// *** requires PHP5 ***
// search for mp3 files
$filter = '.mp3';
// url to be added to the path *** NO TRAILING SLASH ***
$url = 'http://www.littlegraffyx.com/ameisez/mplayer';
// path to the directory you want to scan
$directory = './media';
$it = new RecursiveDirectoryIterator("$directory");
foreach(new RecursiveIteratorIterator($it) as $file)
{
if (!((strpos(strtolower($file), $filter)) === false))
{
$items[] = preg_replace(array("#\\\#", "#\./#"), array("/", "/"), $file);
}
}
arsort($items);
header("content-type:text/xml;charset=utf-8");
print <<<END
<?xml version='1.0' encoding='UTF-8'?>
<playlist version='1' xmlns='http://xspf.org/ns/0/'>
<title>AMEISEZ MEDIA PLAYER FOR PHPBB3</title>
<info>http://www.littlegraffyx.com/ameisez</info>
<trackList>
END;
foreach($items as $item)
{
$title_array = explode('/', $item);
$title = substr(end($title_array), 0, (strlen(end($title_array)) - 4));
print <<<END
<track>
<title>$title</title>
<location>$url$item</location>
<info>http://www.littlegraffyx.com/ameisez</info>
</track>
END;
}
print <<<END
</trackList>
</playlist>
END;
?>
That is working OK but I need 2 options that is present in your code above specifically on your post Feb 18.
Force download and multiple filetype option.
I tried copying your code above but it is giving me error.
See here
http://www.littlegraffyx.com/ameisez/mplayer/pl_all2.php
Maybe you can supply me with something that will fit in my existing code.
Thanks in advance.
ameisez
Sep. 27, 2009Ameisez
Got is sorted out with the help of LOST.
Here are some helpful links to learn more about the JW Player™:
Earn money with ads from LongTail's AdSolution. Watch our demos and sign up now!
If you don’t buy a commercial license, you cannot use a JW Player™ on (i) a site that has ads; (ii) a corporate site; or a (iii) CMS. Our licenses are very inexpensive, so what are you waiting for? Buy a license today.