As long as you make sure the normal headers don't get sent (change
from mime type of text/HTML to the appropriate one for the playlist),
you should be able to just echo/sprintf() the file (both are ASCII
formats). Just note that Windows Media player is terminally stupid and
will not read the file correctly (foobar2000 and VLC have no issue
with it)... my example code (PLS format):
/*
Copyright 2011 John Havlik (email :
mtekk...@gmail.com)
This program is free software; you can redistribute it and/or
modify
it under the terms of the GNU General Public License as published
by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
02110-1301 USA
*/
//Start our playlist stream, based off of three songs on my local
testbed
$songs = array(
array(
'title' => 'All of the Lights [Explicit]',
'artist' => 'Kanye West',
'duration' => '00:04:59',
'location' => '
http://atomtux/tools/05%20-%20All%20Of%20The%20Lights
%20[Explicit].mp3'
),
array(
'title' => 'Coming Home',
'artist' => 'Diddy',
'duration' => '00:03:58',
'location' => '
http://atomtux/tools/18%20-%20Coming%20Home.mp3'
),
array(
'title' => 'Erase Me',
'artist' => 'Kid Cudi',
'duration' => '00:03:13',
'location' => '
http://atomtux/tools/Kid%20Cudi%20-%20Erase%20Me.mp3'
)
);
//Need to send our proper headers so browser doesn't read as text/HTML
header('Content-type: audio/x-scpls');
//Gives the playlist a nice name rather than filename.php
header('Content-Disposition: attachment; filename="playlist.pls"');
echo "[playlist]\n";
//Add in our songs
$song_count = 1;
foreach($songs as $song)
{
echo "File$song_count=" . $song['location'] . "\n";
echo "Title$song_count=" . $song['artist'] . ' - ' . $song['title'] .
"\n";
echo "Length$song_count=" . $song['duration'] . "\n";
$song_count++;
}
//Echo the track count
echo "NumberOfEntries=$song_count\n";
//Echo our PLS version
echo "Version=2";
?>
-John Havlik
On May 5, 10:43 pm, Toby Cryns <
tcr...@gmail.com> wrote:
> Thanks for the help thus far. I feel like I am headed in the right
> direction, but I am still a bit confused about how to put all the pieces
> together to create an online audio player.
>
> I can see the format that the m3u or pls files need to have (Thanks, Nick!).
> Do I need to write to a txt file like this tutorial points out:
http://php.about.com/od/advancedphp/ss/file_write_php.htm? Is there a
> better way to address that? I am comfortable using the loop to build a
> playlist, but I haven't outputted a file via php in a few years, so I am a
> bit rusty there.
>
> Also, I could not find any reference to an enclosure in my source or in my
> feed. Any thoughts on where to look for that?
>
> Will the m3u and/or pls file be playable in an *online* audio player? It