Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-19-2009, 05:06 PM   PM User | #1
Angelin
New Coder

 
Join Date: Nov 2009
Location: Sibiu, Romania
Posts: 11
Thanks: 0
Thanked 6 Times in 6 Posts
Angelin is an unknown quantity at this point
Receiving shoutcast stream with php but with "impurities"

Hello everyone!
I'm working on a project that requires small flash player to stream an online shoutcast radio. Due to security reasons the flash player can stream only local files. So I had to come up with another solution... I found a php script that reads a shoutcast stream and outputs it in mp3 format.

Now my player works, but the sound is received with some "impurities", or "clicks"... I don't know how to call them. Basically, from ten to ten seconds there is a short annoying sound.

This is the script that I use:

PHP Code:
<?php
set_time_limit
(0);

$streamname "205.188.215.229";
$port "8018";
$path "/;stream.mp3";

header("Content-type: audio/mpeg"); 
$sock fsockopen($streamname,$port); 

fputs($sock"GET $path HTTP/1.0\r\n"); 
fputs($sock"Host: $streamname\r\n"); 
fputs($sock"User-Agent: WinampMPEG/2.9\r\n"); 
fputs($sock"Accept: */*\r\n"); 
fputs($sock"Icy-MetaData:1\r\n"); 
fputs($sock"Connection: close\r\n\r\n"); 


while(!
feof($sock)) {
        
$buf fread($sock1024 6);
        echo 
$buf;
}

fclose($sock);  
?>
If you add the path to this file in winamp or any other streaming player, you will hear the radio including the "impurities".

I'm sure it's the script's fault because if I try to listen to the radio directly the sound is pure. :confused:

I tied also

PHP Code:
fpassthru($sock); 
instead of

PHP Code:
 while(!feof($sock)) {
        
$buf fread($sock1024 6);
        echo 
$buf;

but ended up with the same result. Any help would be greatly appreciated!
Thanks!
Angelin is offline   Reply With Quote
Old 11-20-2009, 12:48 AM   PM User | #2
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
Quote:
Originally Posted by Angelin View Post
I'm sure it's the script's fault because if I try to listen to the radio directly the sound is pure.
I kinda doubt that because the script isn't converting the binary stream(in theory)... it's just outputting the data. I would guess it has something to do with the player losing the buffer and attempting to compensate, or converting the audio before outputting it. There are ways around the flash player's security controls(legitimate ones -- not a PHP proxy).
Inigoesdr is offline   Reply With Quote
Old 07-06-2011, 08:33 AM   PM User | #3
maxmob
New to the CF scene

 
Join Date: Jul 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
maxmob is an unknown quantity at this point
Hi Angelin,

Are you sure that you are getting a continuous streaming from this code ? because I am also using the same code but after 2/3 minutes song getting stop automatically. If you have any idea about that... please share me with the solution.
maxmob is offline   Reply With Quote
Old 09-21-2011, 04:16 PM   PM User | #4
marcalle
New to the CF scene

 
Join Date: Sep 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
marcalle is an unknown quantity at this point
Has anyone found a solution to this? I would love to use this for my station!

I get it to work continuously (60+ minutes), however it does have that chirp in it.

Thanks for anyones help!
marcalle is offline   Reply With Quote
Old 09-21-2011, 06:15 PM   PM User | #5
DanInMa
Senior Coder

 
DanInMa's Avatar
 
Join Date: Nov 2010
Location: Salem,Ma
Posts: 1,307
Thanks: 12
Thanked 204 Times in 204 Posts
DanInMa is on a distinguished road


a little humor
__________________
- Firebug is a web developers best friend! - Learn it, Love it, use it!
- Validate your code! - JQ/JS troubleshooting
- Using jQuery with Other Libraries - Jslint for Jquery/other JS library users
DanInMa is online now   Reply With Quote
Old 09-21-2011, 07:33 PM   PM User | #6
marcalle
New to the CF scene

 
Join Date: Sep 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
marcalle is an unknown quantity at this point
Quote:
Originally Posted by DanInMa View Post


a little humor
I dont see anything lol.

I think what I need to do with this code is convert it to binary format, which I dont have the knowledge to do. Im hoping someone around the forums here may have that knowledge.
marcalle is offline   Reply With Quote
Old 09-21-2011, 08:30 PM   PM User | #7
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
Quote:
Originally Posted by marcalle View Post
I think what I need to do with this code is convert it to binary format, which I dont have the knowledge to do. Im hoping someone around the forums here may have that knowledge.
No, you are misunderstanding. You don't need to convert it to anything else as the result will be the same. The code that was posted is really simple and there is nothing there that would explain the random-ish "impurities". All it does it relay information on the HTTP protocol, and pretty inefficiently at that.

The problem almost certainly lies with the server or the transport. If you have access to the website you should use a crossdomain.xml like I mentioned previously, and connect to the server directly.
Inigoesdr is offline   Reply With Quote
Old 09-21-2011, 09:00 PM   PM User | #8
marcalle
New to the CF scene

 
Join Date: Sep 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
marcalle is an unknown quantity at this point
Okay...I guess I dont know enough about an xml to do that. I'm trying to take a shoutcast MP3 stream and play it via php like this website: http://www.shoutcaststreaming.us/android.php

or like this site:

http://s6.viastreaming.net/mobile.php?port=7010

Both use the same streaming technology I use, I just want to figure out how to do the PHP rendering as it works great on android!
marcalle is offline   Reply With Quote
Old 09-21-2011, 10:44 PM   PM User | #9
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
Quote:
Originally Posted by marcalle View Post
Okay...I guess I dont know enough about an xml to do that.
There is no XML anywhere in the code above.
Quote:
Originally Posted by marcalle View Post
Both use the same streaming technology I use, I just want to figure out how to do the PHP rendering as it works great on android!
Are you using the same player for both their site and yours? Are you sure they use the exact same technology?

Like I said, using code like this is pretty inefficient because it has to keep the connection open to both the remote server and the user streaming at the same time, and it involves an HTTP relay invoking PHP which uses more memory on the relay server. PHP is not designed for long-running applications and it's generally a bad idea to try to make it keep running indefinitely.
Inigoesdr is offline   Reply With Quote
Old 05-02-2012, 11:53 PM   PM User | #10
marcalle
New to the CF scene

 
Join Date: Sep 2011
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
marcalle is an unknown quantity at this point
Im referring to the technology SHOUTcast actually. I apologize for the delay, I've been in the hospital for the last 6 months.

I'm looking for this so I can open it with android.
marcalle is offline   Reply With Quote
Old 12-14-2012, 05:43 PM   PM User | #11
gagan.juneja
New to the CF scene

 
Join Date: Dec 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
gagan.juneja is an unknown quantity at this point
Hello,

Can you please share the final code that you are using.

Regards,
Gagan
gagan.juneja is offline   Reply With Quote
Reply

Bookmarks

Tags
radio, soutcast, streaming

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 12:01 PM.


Advertisement
Log in to turn off these ads.