Home     Services     About     News     Blog     Contact

 
 
 
 
Blog

Dynamic M3U playlist with PHP and MySQL
     Added on 01/06/07 by Kris


Podcasters listen up. I wanted to create a playlist (M3U file) in a couple varieties, one: recent podcasts (the last 30) and two: all podcasts. You would think this would be a simple thing to do with PHP and MySQL . . . nope. WordPress users might find this handy.

I did succeed (recent playlist).

Here's how I got it done:

1) Add a mod_rewrite line to your .htaccess file that ends with '.m3u' like so:
RewriteRule ^playlist/all/playlist.m3u$ http://www.yourdomain.com/yourscript.php?type=$1
2) Create the PHP script to generate the M3U data structure:
a. connect to your MySQL database
b. query your live podcasts (the ones in your cms like WordPress not labled draft. You'll most likely need to know the data type it submits to this field in the database like '0' or '1')
c. pull up the post id, post title and podcast file
3) Lie to the browser by writing a header for an M3U file:
header("content-type: audio/x-mpegurl");
4) Write this line without 'echo' or 'print':
#EXTM3U
5) Create a loop to write your podcast id, podcast title and podcast URL

6) The M3U output, which you shouldn't see in the browser if you do this right (I know I saw it for about an hour) looks like:
#EXTM3U
#EXTINF:597,Betsy and her husband Kris Jan 01, 2007
http://www.croncast.com/show/597/cks-2007-01-01.mp3
#EXTINF:596,Betsy and her husband Kris Dec 29, 2006
http://www.croncast.com/show/596/cks-2006-12-29.mp3
I am not a super coder but this should be enough to get you going. And just in case that it isn't look below for the exact (well, nearly exact script that I am using).



Tags: dynamic m3u , m3u php , m3u from php , m3u php mysql , dynamic m3u from php


 
 



 
 
 


Website contents: Podcasts, Copy and Graphics are © Copyright 2005-2009 Palegroove, Inc. unless otherwise noted.