Streaming Music

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aliasxneo
Forum Contributor
Posts: 136
Joined: Thu Aug 31, 2006 12:01 am

Streaming Music

Post by aliasxneo »

Is it possible to stream music with PHP? I'm looking to create an online radio script, nothing too advanced (just plays random music files) but am wondering how I would stream the music. I know I want to use PHP for the back-end for adding and editing the playlist, but streaming is something I've never done before. Can someone shed some light on this?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Streaming Music

Post by Christopher »

I think there as a php based streaming solution around somewhere. Have you searched? I think it may be pseudo-streaming, but it may do what you want.
(#10850)
aliasxneo
Forum Contributor
Posts: 136
Joined: Thu Aug 31, 2006 12:01 am

Re: Streaming Music

Post by aliasxneo »

arborint wrote:I think there as a php based streaming solution around somewhere. Have you searched? I think it may be pseudo-streaming, but it may do what you want.
I see a lot of stuff for streaming video (Flash etc.) but nothing with audio.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Streaming Music

Post by Christopher »

Audio streaming typically uses the same players as video players -- just no video window. Flash is commonly used for both.
(#10850)
aliasxneo
Forum Contributor
Posts: 136
Joined: Thu Aug 31, 2006 12:01 am

Re: Streaming Music

Post by aliasxneo »

arborint wrote:Audio streaming typically uses the same players as video players -- just no video window. Flash is commonly used for both.
Well somehow I still havn't found anything. Most I found was something with Real Media Player which wouldn't work to my knowledge with live streaming (i.e I believe Real is just for one song at a time).
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: Streaming Music

Post by Kieran Huggins »

Streaming is definitely possible with PHP, just fpassthru() the file. If you want to limit the bandwidth you can stream so much data and then sleep for a second, wash, rinse, repeat.
aliasxneo
Forum Contributor
Posts: 136
Joined: Thu Aug 31, 2006 12:01 am

Re: Streaming Music

Post by aliasxneo »

Kieran Huggins wrote:Streaming is definitely possible with PHP, just fpassthru() the file. If you want to limit the bandwidth you can stream so much data and then sleep for a second, wash, rinse, repeat.
So how exactly does that work?

Code: Select all

<?php
 
header("Cache-Control: ");
header("Content-Type: audio/mpeg");
header("Content-Transfer-Encoding: binary");
 
$fp = fopen("Airbase.mp3", 'rb');
fpassthru($fp);
exit;
 
 
?>
This is what I got, and it almost seems to be working except it's only streaming like the first 2 seconds of the song. You can see it here:

http://youthapologetics.net/test/test.php

Any idea?
Post Reply