14 January 2008

AS3 mp3 streaming problem with Facebook

I created a Flash game for Facebook and had a problem with the audio I was streaming through the Sound class. Loud clicks, pops and squelches ruined the audio, hurt my ears and probably didn't do my speakers any good!

This problem only occurred when the swf was embedded in Facebook, tests on other servers did not produce this error.

To fix this problem I did the following:

  • Set Securtiy.allowDomain("foo.com"); in the document class

  • I also specifically set the policy file with Security.loadPolicyFile("http://www.foo.com/crossdomain.xml");

  • In crossdomain.xml, add the to-ports attribute:
    <allow-access-from domain="www.foo.com/" secure="false" to-ports="*" />

This removed all clicks, bleeps and squelchy noised from the audio. I guess it has something to do with Flash only granting access to ports 1024 and above by default. Specifying to-ports="*" presumably allowed access to all available ports below 1024 and the mp3 streamed without any problems.

This documentation helped: Security.loadPolicyFile()

1 comment:

angelo said...

Please, man, you've got to help me with this... I got the same problem with this app: http://www.vanilla-mi.com/eastpak/eng/myIndex.swf

In my document class i put




In this last case, in my crossdomain.xml i put just:

allow-access-from domain="*" secure="false" to-ports="*"

This shouldallow whatever domain to whatever port, am I right with this?

But the mp3 stream is still crappy. Where did I get lost?