HOT TOPIC: Shoutcast/Icecast in FLash!
Hi everybody,
I am trying to build an mp3 player in Macromedia Flash that would work with Icecast.(better than Shoutcast). 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)
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).
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 sent 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 = "my.radio.com"; // 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.
I noticed Flash access the php script only if it is in the same domain. No error appears when I call the script from another domain [TestIcecast.loadSound("http://whatever.com/script.php", true);], but I discovered flash would not access the script by analyzing my server logs. Instead, the script must be on the same domain and have to be called directly like that: TestIcecast.loadSound("script.php", true);
Is there any header information missing in my php script? Do you think the problem might come from the Flash player’s security policy? Can Flash 2004 solve this problem? Note that the same problem happens with Shoutcast.
Thank you very much for any help!
MAX
|