Stream MP3 using PHP – m3u

On April 11, 2010, in Fedora, LAMP, Linux, PHP, Tips, Tricks, Web Services, by Sandeep Verma

Hits: 680  

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
………………

http://www.domain.com/mp3/svnlabs/1.mp3

http://www.domain.com/mp3/svnlabs/2.mp3

http://www.domain.com/mp3/svnlabs/3.mp3

……………………

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

LimeExchange LimeExchange - Online Services Marketplace


Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...