Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New Coder
    Join Date
    Nov 2009
    Location
    Sibiu, Romania
    Posts
    11
    Thanks
    0
    Thanked 6 Times in 6 Posts

    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!

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    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).

  • #3
    New to the CF scene
    Join Date
    Jul 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!

  • #5
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts


    a little humor

  • #6
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #7
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    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.

  • #8
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!

  • #9
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    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.

  • #10
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #11
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hello,

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

    Regards,
    Gagan


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •