Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Streaming MP3 Audio stream "through" a php file.
Old 02-13-2009, 09:28 PM Streaming MP3 Audio stream "through" a php file.
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
Hi,

Okay so i need to setup a file which can preform checks before allowing a user to access a stream of audio (shoutcast) so for instance the PHP will check which country they are from if allowed stream audio else exit or stream another stream (saying sorry you cannot listen to this stream in your country)....

How can i do it?

It seems easy with single files but obviously not with a continuous stream of audio so i need to know how and pretty quickly.

I have searched like mad for this and cant find anything which seems to show what i am looking for.

Any help apprieciated greatly, and you will of course get my nice green TP !

Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
 
Register now for full access!
Old 02-14-2009, 02:22 AM Re: Streaming MP3 Audio stream "through" a php file.
Decaf's Avatar
Ultra Talker

Posts: 489
Name: Adam
Trades: 0
Hmm, Sounds like more of a js function that checks a cookie and compares it to a DB permission set? That is if your going to keep users on the same page.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Decaf is offline
Reply With Quote
View Public Profile Visit Decaf's homepage!
 
Old 02-14-2009, 04:30 PM Re: Streaming MP3 Audio stream "through" a php file.
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
http://uk3.php.net/wrappers.audio
http://uk3.php.net/manual/en/ref.stream.php

Something like: (from http://www.bigresource.com/PHP-Regis...-ViCtl7YE.html)
PHP Code:
<?PHP 
//force download dialog
header("Content-type: application/octet-stream");
header("Content-disposition: attachment;
filename="
$file"");
header("Content-transfer-encoding: binary");
header("Content-length: " filesize($path) . "
"
);

//send file contents
$fp=fopen($path"r");
fpassthru($fp);
exit();
?>
could work.
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 02-14-2009, 08:51 PM Re: Streaming MP3 Audio stream "through" a php file.
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
Mike that only works with audio FILES, not streams because the filesize is continuously increasing....

Looked at those pages and they dont seem to be what i am looking for :s.

Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 02-15-2009, 12:37 PM Re: Streaming MP3 Audio stream "through" a php file.
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
You should a proxy style script then maybe. I think in this case, the extra server load could prove to be fruitless.
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 02-16-2009, 09:48 PM Re: Streaming MP3 Audio stream "through" a php file.
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
Any examples :/

The problem with proxy scripts is they work by the server downloading a file and then resending it to the end user.

Streams work in a totally different way, as in effect the server takes a bit of stream and then hands it straight on to the end user.

Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 02-17-2009, 04:43 AM Re: Streaming MP3 Audio stream "through" a php file.
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
In fact, it's easier than I thhought.
Here Dan, tested and approved:
PHP Code:
<?php
set_time_limit
(0);
//digitally-imported.fm electro-house mp3 stream. Please bare with me.
define('SRC_URL''http://scfire-ntc-aa03.stream.aol.com:80/stream/1025');
$strContext=stream_context_create(
    array(
      
'http'=>array(
        
'method'=>'GET',
        
'header'=>"Accept-language: en\r\n"
      
)
    )
  );
$fpOrigin=fopen(SRC_URL'rb'false$strContext); //open a binary compatible stream
header('content-type: application/octet-stream');   //setup the current user session
while(!feof($fpOrigin)){
  
$buffer=fread($fpOrigin4096); //we read chunks of 4096 bytes
  
echo $buffer//And we send them back to the current user
  
flush();  //we try to flush the output buffer, in case there is a deflated or gzipped transfert betweenm the web server and the client
}
fclose($fpOrigin);
?>
If you open this from winamp, you will get the stream that is defined into SRC_URL.
As we just take bit of 4096 bytes at a time, we don't need to know the total size of the stream.
We just send back small chunks, until we got nothing more or the script stops.
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 02-17-2009 at 04:44 AM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-17-2009, 04:19 PM Re: Streaming MP3 Audio stream "through" a php file.
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
Thanks tripy will test it out and you can expect some nice green TP in a bit

Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 02-17-2009, 04:38 PM Re: Streaming MP3 Audio stream "through" a php file.
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
Erm, it dont work.

Computer says:

Warning: fopen(http://scfire-ntc-aa03.stream.aol.com:80/stream/1025) [function.fopen]: failed to open stream: HTTP request failed! ICY 200 OK in /home/USER/public_html/stream.php on line 13

Warning: Cannot modify header information - headers already sent by (output started at /home/USER/public_html/stream.php:13) in /home/USER/public_html/stream.php on line 14

Warning: feof(): supplied argument is not a valid stream resource in /home/USER/public_html/stream.php on line 15

Warning: fread(): supplied argument is not a valid stream resource in /home/USER/public_html/stream.php on line 16

Warning: feof(): supplied argument is not a valid stream resource in /home/USER/public_html/stream.php on line 15

Warning: fread(): supplied argument is not a valid stream resource in /home/USER/public_html/stream.php on line 16

Warning: feof(): supplied argument is not a valid stream resource in /home/USER/public_html/stream.php on line 15

(the last two errors repeat god knows how many times and kindly crashed my apache when i didnt stop it running the first time! lol. Also seems to have filled up tmp lol... i really do need to upgrade that server :/

Tried it on a few players (winamp, VLC and WMP) but all nothing seemed to connect but no audio.

Any ideas would be helpful :s

Also might be useful to use http://cleese.xdnet.co.uk:8016 which is a stream i host so as to make sure it works in that format.

But this is a pain in the backside got me all excited then lol.

Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 02-17-2009, 05:07 PM Re: Streaming MP3 Audio stream "through" a php file.
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Strange, it's working from my server: http://193.58.255.251/prox.php
Source visible there: http://193.58.255.251/prox.phps

I have to say that Swindon 105.5 is not exactly my type of station...

On linux, I tried playing it in audacious, rhythmbox and they where ok.
From my workplace, on windows XP, I tried with aimp2 and it was working too.
I tried a winamp in a win2k virtual machine, and it's playing ok too.
But windows media player failed on that machine.
A windows media player on my eeepc just does a "blip" though, like it would disconnect. I don't know why...

Maybe some more headers are needed to be "microsoft compatible"...

Edit:
Never mind windows media player 7 on windows 2000, I've let it open, and it eventually started to play.
It looks like it buffer a really large hunk before playing it (I'm an a 10Mbit line though!).
winamp is almost instantaneous.

Edit 2:
Ok, after looking a bit, I've got it playing in wmp 9 on my eeePc too, by adding an header that give the file name and changing the content-type from application/octet-stream to audio/x-mpegurl

Can you try it Dan ?

Edit 3:
****...
Forget about WMP. Neither can work.
I've setup a transparent proxy at home, and wmp was only playing a bit of stream that was fetched by the proxy.
I cannot find why this @#¼ wmp cannot play this stream.
Browsing the winamp technical forums, I've found this: http://forums.winamp.com/showthread....ight=php+proxy
I did not tried it though.
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 02-17-2009 at 06:10 PM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-17-2009, 06:36 PM Re: Streaming MP3 Audio stream "through" a php file.
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Ok, this merit a new post....

It's official, windows media player is the most ****ed up **** that has even be programmed.

This ****er looks at the extension of the url to determine the content !!!!
I had to add an .htaccess like this:
Code:
rewriteengine on
rewritebase /
RewriteRule ^stream.mp3$  prox.php
And now, when wmp opens http://193.58.255.251/stream.mp3 it plays ok.

I cannot believe it!
Sheesh, 1 hour wasted because it doesn't interpret HTTP headers.
Congratulation ********s, you programmed that piece of **** with a master mind...
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-17-2009, 07:45 PM Re: Streaming MP3 Audio stream "through" a php file.
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
Right okay, so just to be clear the above proxy works only in winamp ...

and in wmp (for me at least) only played the inital buffer.

Why cant things be simple ><...

Also if can get this working for all players could there be a way for it to connect using the end users ip, useragent etc...

The idea for this is for a radio station which can only stream to the UK, so it would check their location before connecting, but if i installed this it would would just come up as my server connecting :| which would screw up their stats (which they need for licensing)

Man this is hard work.

**** it why cant shoutcast have geo locking!!!

Dan
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 02-17-2009, 08:03 PM Re: Streaming MP3 Audio stream "through" a php file.
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Hmm, no. For me, it worked with all in the end.
WMP only when using the mod_rewrite to get the .mp3 version.

But winamp, as well as all the other players I tried in linux played it at least for 5 minutes. I just played for 7 minutes of stream without a hitch.
I didn't tried more, but it should not close the connection.

Quote:
but if i installed this it would would just come up as my server connecting :| which would screw up their stats (which they need for licensing)
Yep, it will.
And your server will consume a lot of bandwidth.
96Kbit * the number of users * 2
* 2 because your server download a copy of the stream, and send back the same to the connected user.

It does not seems like this is the good solution.
I'm sorry, we have hit the limits of my streaming knowledge.
I have no idea how you could restrict by country without proxying it...
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 02-17-2009, 08:09 PM Re: Streaming MP3 Audio stream "through" a php file.
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
Yes, well the streaming server has unlimited bandwidth but currently i dont have the server all to myself or any real control, and i dont yet have a server of my own (which the one i want includes unmetered bandwdith) so that would eat in quite a bit to my server at the moment

O well looks like im going to have some fun
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 02-17-2009, 08:23 PM Re: Streaming MP3 Audio stream "through" a php file.
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Yup, looks like it.
By the way, I took down the script.
The .phps is still there, if anyone needs it for reference, but I didn't wanted to let that bandwidth sucker in place and open to anyone.
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to Streaming MP3 Audio stream "through" a php file.
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 1.94352 seconds with 12 queries