Stream MP3 using PHP – m3u

M3U is a computer file format that stores multimedia playlists.

<?php

function m3u_stream($dir) {

$mp3=””;
$siteurl=”http://www.domain.com/mp3/”;

$h1 = opendir($dir);

while ($file = readdir($h1))
{

if ($file == ‘.’ || $file == ‘..’) continue;
$mp3.=$siteurl.basename($dir).”/”.$file.”\r\n”;

}

closedir($h1);

return $mp3;

}

$folder = “svnlabs”;

file_put_contents($folder.”.m3u”, m3u_stream($_SERVER[“DOCUMENT_ROOT”].”/mp3/”.$folder.”/”));

?>

Here “svnlabs” is a folder where all mp3 files exists… this program will create svnlabs.m3u playlist file using php script.

svnlabs.m3u file contents all mp3 links with domain “http://www.domain.com/mp3/”

svnlabs.m3u
………………



……………………

Now http://www.domain.com/mp3/svnlabs.m3u can be used for streaming mp3 from www.domain.com