Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

fishkorp

macrumors 68030
Original poster
Apr 10, 2006
2,536
650
Ellicott City, MD
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).
 

zub3qin

macrumors 65816
Apr 10, 2007
1,314
2
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).

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???
 

jaXed

macrumors newbie
Sep 19, 2007
7
0
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!
 

zub3qin

macrumors 65816
Apr 10, 2007
1,314
2
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!

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!
 

fishkorp

macrumors 68030
Original poster
Apr 10, 2006
2,536
650
Ellicott City, MD
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!

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.
 

jaXed

macrumors newbie
Sep 19, 2007
7
0
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.

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.
 

melsom

macrumors newbie
Sep 20, 2007
1
0
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);
        }  
           
}          
           
?>
 

coderchen

macrumors newbie
Sep 27, 2007
1
0
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:
 

fishkorp

macrumors 68030
Original poster
Apr 10, 2006
2,536
650
Ellicott City, MD
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:

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.
 

idobi

macrumors newbie
Oct 16, 2007
3
0
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.
 

tnakasaki

macrumors newbie
Nov 2, 2007
2
0
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.

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, $errstr, 30) 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($fp, 1024);		
			
			//while pointer is not at EOF
			//get next line
			$buf = fgets($fp, 1024);			
			//delete trash (shoutcast headers)
			$buf = fgets($fp, 1024);
			$buf = fgets($fp, 1024);
			$buf = fgets($fp, 1024);
			$buf = fgets($fp, 1024);
			$buf = fgets($fp, 1024);
			$buf = fgets($fp, 1024);
			$buf = fgets($fp, 1024);
			 
			//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($fp, 1);
				
				//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();
	}
 

tnakasaki

macrumors newbie
Nov 2, 2007
2
0
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
 

CarlsonCustoms

macrumors 6502
Mar 5, 2007
387
0
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
 

fishkorp

macrumors 68030
Original poster
Apr 10, 2006
2,536
650
Ellicott City, MD
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

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.
 

JP3G

macrumors member
Nov 1, 2008
70
0
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!
 

calvintcow

macrumors newbie
May 26, 2011
1
0
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).

Can you let me know how to do the PHP to let the Macox open up the quicktime controller to play the stream? :)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.