SHOUTCast on iPhone?

Discussion in 'Jailbreaks and iOS Hacks' started by fishkorp, Sep 17, 2007.

  1. fishkorp macrumors 68020

    fishkorp

    Joined:
    Apr 10, 2006
    Location:
    Ellicott City, MD
    #1
    Anyone have a solution yet to listen to SHOUTcast streams on an iPhone? I tried some basic PHP manipulation to "trick" the browser, which works on desktop Safari to open a QuickTime control, but on the iPhone it shows the play button with a line through it. Just wondering if anyone came up with any web-based solution for it, or if there's a 3rd party radio app out there I can try (haven't hacked the phone yet, but will after the next update).
     
  2. zub3qin macrumors 65816

    zub3qin

    Joined:
    Apr 10, 2007
    #2
    This iPhone is so frustrating... so advanced yet it can't do many many things my old Treo 700p does. I can stream nearly all web audio and video using a rather primitive browser (Blazer)..... Why can't safari???
     
  3. jaXed macrumors newbie

    Joined:
    Sep 19, 2007
    #3
    I have created a cgi script that connects to a shoutcast stream and returns the stream to the browser as if it were an mp3 file. This works in Safari on the mac and PC but not on the iPhone. I have compared the http headers that are sent when you click on an mp3 file, which plays on the iPhone, and my cgi script and see no differences. Sure, this is not a perfect solution - but I need my streams!
     
  4. zub3qin macrumors 65816

    zub3qin

    Joined:
    Apr 10, 2007
    #4
    Do you know a way to stream the following on an iPhone?

    http://core.crystalone.net:9000/listen.pls
    or
    http://core.crystalone.net:9000/

    Thanks!
     
  5. jaXed macrumors newbie

    Joined:
    Sep 19, 2007
    #5
    No, I don't have it working on the iphone. Even if I do get it to work, the solution is not as elegant as having a shoutcast.app or some other specific streaming app for the iphone. 3rd party devels, where are you?
     
  6. fishkorp thread starter macrumors 68020

    fishkorp

    Joined:
    Apr 10, 2006
    Location:
    Ellicott City, MD
    #6
    that's the situation i'm in. i can get destkop Safari to play my PHP "spoof" just fine, it thinks it's a regular MP3. but the iPhone Safari won't play it. I even tried setting a content size and fake file name, and still no luck. i have no idea why'd they'd prevent that from working.
     
  7. jaXed macrumors newbie

    Joined:
    Sep 19, 2007
    #7
    Time to get technical -

    These are the header values I explicitly set:

    print "Accept-Ranges: bytes\n";
    print "Content-Length: $len\n";
    print "Content-Disposition: inline; filename=\"stream.mp3\"\n";
    print "Content-Type: audio/mpeg\n";
    print "\n";


    DOES NOT WORK on the iPhone - but works in regular old browsers, Mac and PC Safari included. Obviously, it plays for just "Content-Length" amount of time, but it works.

    One thing I notice in my web logs when the iPhone access my cgi, first Safari on the iPhone attempts to access it, and then I see the Quicktime on the iPhone try to get at the cgi. So there are two hits on my cgi script. Perhaps there needs to be additional trickery in the cgi script to handle that.
     
  8. melsom macrumors newbie

    Joined:
    Sep 20, 2007
    #8
    Maybe this is something you can work with. Had it working for a while, by running the script locally as CGI, but the iPhone will only play the length of the mp3 file it registered when it was opened. Maybe there is a way to get around that?

    Code:
    <?
    
    $fp = fsockopen("sc3.radioseven.se", "8500", $errno, $errstr, 30) or die("Unable to connect to server!");
    
    $buf = "GET / HTTP/1.0\r\nIcy-MetaData:0\r\n\r\n";
    fwrite($fp, $buf);
    $buf = fgets($fp, 1024);
    
    while (!feof($fp))  {
            $buf = fgets($fp, 1024);
            if ($buf == "\r\n") {
                    break;
            }
            $fout = fopen("dump.mp3", "w");
            while (!feof($fp)) {
                    $buf = fread($fp, 512);
                    fwrite($fout, $buf);
            }  
               
    }          
               
    ?>         
    
     
  9. coderchen macrumors newbie

    Joined:
    Sep 27, 2007
    #9
    Shoutcast hack

    One alternative (don't laugh). Can one just add "blank" video to the audios and upload to YouTube and then listen through the YouTube on the iPhone? :apple:
     
  10. fishkorp thread starter macrumors 68020

    fishkorp

    Joined:
    Apr 10, 2006
    Location:
    Ellicott City, MD
    #10
    you're not listening to live internet radio that way. i'm looking for a way to listen to the station as it's playing.
     
  11. idobi macrumors newbie

    Joined:
    Oct 16, 2007
    #11
    It's not enough to spoof the stream as a file. The iPhone makes an additional request for data at x byte, which doesn't yet exist for a stream. Since it fails, it never starts playing the "file".

    Haven't found a way around it yet.
     
  12. tnakasaki macrumors newbie

    Joined:
    Nov 2, 2007
    #12
    fooling around with molsom's code, i wrote a quick and dirty solution. its not perfect, but you'll get live radio this way. with some 1 or 2 second repeats here and there. the trick was in faking the HTTP 206 headers. excuse my sloppy code :p

    the first request from the iphone tells it that the file is x bytes long (8097152 was just some random number i typed). on the second request the iphone asks for bytes 0 and 1, to test the server for resume capabilities (which will be faked). on the third request and on, the iphone asks for real data, which is fetched on the fly from the shoutcast server

    PHP:
    $headers http_get_request_headers();
            
            if (isset(
    $headers['Range'])) {
                
    $exploded_range explode('='$headers['Range']);
                
    $limits explode('-'$exploded_range[1]);
                
    $length = ($limits[1] - $limits[0]) + 1;
                
    $content_range 'bytes ' $limits[0] . '-' $limits[1];
                
                
    header('HTTP/1.1 206 Partial Content');
                
    header('Accept-Ranges: bytes');            
                
    header('Content-Length: ' $length);
                
    header('Content-Range: ' $content_range '/8097152');
                
    header('Content-type: audio/mpeg');
                
                
    //open the stream, set as resource $fp
                
    $fp fsockopen("stream.cerritosallstars.com""80"$errno$errstr30) or die("Unable to connect to server!");
                
                
    //HTTP commands
                
    $buf "GET / HTTP/1.0\r\nIcy-MetaData:0\r\n\r\n";
                
                
    //send HTTP commands in string $buf to stream $fp
                
    fwrite($fp$buf);
                
                
    //get next line from stream
                
    $buf fgets($fp1024);        
                
                
    //while pointer is not at EOF
                //get next line
                
    $buf fgets($fp1024);            
                
    //delete trash (shoutcast headers)
                
    $buf fgets($fp1024);
                
    $buf fgets($fp1024);
                
    $buf fgets($fp1024);
                
    $buf fgets($fp1024);
                
    $buf fgets($fp1024);
                
    $buf fgets($fp1024);
                
    $buf fgets($fp1024);
                 
                
    //break if EOF
                
    if ($buf == "\r\n") {
                    break;
                }
                
                
    $bytes_sent 0;
                
                
    //while pointer is not at EOF, and not too many bytes are sent...
                
    while (!feof($fp) AND ($bytes_sent $length)) {
                    
    //read 1 byte of stream
                    
    $buf fread($fp1);
                    
                    
    //output byte to iphone;
                    
    echo $buf;
                    
    $bytes_sent++;
                }
                
    fclose($fp);
                exit();
            }
            else {
                
    header('Accept-Ranges: bytes');    
                
    header('Content-Length: 8097152');
                
    header('Content-type: audio/mpeg');
                
                echo 
    'blah';
                exit();
            }
            exit();
        }
     
  13. tnakasaki macrumors newbie

    Joined:
    Nov 2, 2007
    #13
    i just realized that apache and php have been ported to iphone, and with a little work you probably dont need to host this script anywhere. i'll try this out hopefully within the next week
     
  14. fuelishways macrumors newbie

    Joined:
    Jun 18, 2008
    #14
    How does this script actually work? Does it stream m3u files?
     
  15. CarlsonCustoms macrumors 6502

    Joined:
    Mar 5, 2007
    #15
    Why can't you use Nullrivers Tuner or Fstream?

    Leo Laporte streams his shows live on twit.am using a shoutcast (or is it icecast?) stream and I use those two programs to listen.


    Zack
     
  16. ProRadio macrumors newbie

    Joined:
    Feb 19, 2009
    #16
  17. fishkorp thread starter macrumors 68020

    fishkorp

    Joined:
    Apr 10, 2006
    Location:
    Ellicott City, MD
    #17
    Because when I made this thread over a year ago there was no App Store so those didn't exist ;)

    It's a moot point now, so this thread can probably be locked.
     
  18. mozyr(br) macrumors newbie

    Joined:
    Mar 10, 2009
    #18
  19. JP3G macrumors member

    JP3G

    Joined:
    Nov 1, 2008
    #19
    There is an excellent software called FStream, that can play Shoutcast via WIFI and 3G. I use it in my car all the time.

    And it's free!
     
  20. calvintcow macrumors newbie

    Joined:
    May 26, 2011
    #20
    Can you let me know how to do the PHP to let the Macox open up the quicktime controller to play the stream? :)
     

Share This Page