[icecast-dev] Hot Topic: Icecast in Macromedia Flash

Macsym
Fri, 06 Aug 2004 14:57:35 -0000

Hi everybody,
I am trying to build an mp3 player in Macromedia Flash that would work with
Icecast. Using Flash as a mp3 player instead of Winamp, XMMS,. could
democratize Icecast because Flash is cross-platform/cross-browser, it is
installed on almost every computer connected to the internet and it will be
embedded into a webpage.
I successfully imported an Icecast live stream into Flash with this simple
ActionScript code:
TestIcecast = new Sound();
TestIcecast.loadSound("http://myradio.com:8000/mystream", true);
TestIcecast.start(0,0)

For those who don't know flash, here is the process of creating a flash
animation: you edit the code into a .fla file, then export this code into a
.swf file (the flash animation) and then embed this flash animation into a
webpage.
HERE IS THE PROBLEM: the code above works perfectly in a standalone swf file
but not when the swf is embedded into a webpage.

I analyzed the logs of my icecast server to understand what is happening:

When I run the swf in standalone mode (not embedded), the ACCESS log is:
192.168.0.3 - - [27/Nov/2003:04:37:46 Romance Standard Time] "GET /mystream
HTTP/1.1" 200 246535 "(null)"
"http://192.168.0.4:37/mystream" 13712368.

When I run the webpage in which the swf is embedded in, I can see the swf
contacts the server but no stream is played. The ACCESS log is:
192.168.0.3 - - [27/Nov/2003:04:42:58 Romance Standard Time] "GET /mystream
HTTP/1.1" 200 328981 "(null)" "-" 13712464

I both case, the ERROR log is:
[.]Client connected
[.]Source found for client
[.[Client added

It means the swf, even when embedded, can access the stream (but it doesn't
play anything). Anyway, I noticed the only difference between the two ACCESS
logs is the "http://192.168.0.4:37/mystream" (in first log) instead of
"-"
(in second log) that appears behind "(null)". Please not that I made
other
tests with Winamp and the habitual information that appears behind
"(null)"
is "-".

I thought the problem might come from the headers that Icecast need to
receive from regular players (Winamp,.) before sending the stream because I
think my Flash animation doesn't send any header information when embedded
into a webpage (headers information is send by the browser instead). For
this reason I tried to use a php script that sends hardcoded header
information (Content-type: audio/mpeg; GET <path of the stream> HTTP/1.1;
protocol: \"http\") to the server. Then I call the URL of this script
into
my flash code instead of the URL of the stream. The php script is:
<?php
$streamname = "192.168.0.4"; // put in whatever stream you want to
play
$port = "37"; // put in the port of the stream
$path = "/mystream"; // put in any extra path, this is usually just a
/
header("Content-type: audio/mpeg");
$sock = fsockopen($streamname,$port);
fputs($sock, "GET $path HTTP/1.1\n");
fputs($sock, "protocol: \"http\"\n");
fputs($sock, "Connection: close\n\n");
fpassthru($sock);
?>
I still have the same problem even with the script: I can listen to the
stream when I run the swf in standalone mode but NOT when it is embedded
into a webpage. I also analyzed the access logs of Icecast when I call the
php script into my flash animation instead of the direct source URL (this
test was realized with the swf embedded):

192.168.0.5 - - [27/Nov/2003:04:54:03 Romance Standard Time] "GET /mystream
HTTP/1.1" 200 94383 "(null)" "-" 4549088

You can notice that it creates the exact same log if I use the php or the
direct stream source when I test my swf embedded.

Is there any header information missing in my php script? What header
information do I have to add in order to send the
"http://192.168.0.4:37/mystream" information (instead of
"-") that appears
after "(null)" into the ACCESS log (mentioned above)??? Do you think
the
problem might come from the the macromedia Flash player's security policy?
Note that the same problem happens with Shoutcast. Also, I have heard that
it worked with Icecast1! Do you have an idea of what modification in
Icecast2 could avoid it to work?

Thank you very much for any help!