MysticEarth
MysticEarth

Reputation: 2806

Loading Sound gives exception on Sound.id3

When loading a MP3 to a flash.media.Sound object the id3 property gives an error:

SecurityError: Error #2000: No active security context.

Offcourse, like many errors in Flex, the Flex documentation doesn't mention a thing about this, except that it exists...

The MP3 is valid (i've checked it with MediaPlayer and iTunes), the Sound object is in a good state (bytesTotal and bytesLoaded both reflect the correct amount of bytes).

Has anyone had this problem too? Any solutions or suggestions?

Upvotes: 0

Views: 675

Answers (1)

George Profenza
George Profenza

Reputation: 51837

Your MP3 should be fine.

If you want to access more data about your mp3 file, rather than just play, you will need a policy file that allows it. Similar to loading an image, if you just add it to the display it and don't access the pixels, it's all good, but if you want to access the pixels you should have permission(a crossdomain xml).

For images, when you call the load image, you can pass a LoaderContext in which you explicitly say you want to check for a crossdomain.xml file and get access to the content.

Similarly you should create a SoundLoaderContext with the second parameter set to true(to check) and use that in the sound load call.

e.g.

var snd:Sound = new Sound();
            var req:URLRequest = new URLRequest("yourSound.mp3");
            var context:SoundLoaderContext = new SoundLoaderContext(0, true);

            snd.load(req, context);
            snd.play();   

For ID3 data you should listen for the ID3 event:

sound.addEventListener(Event.ID3, onID3);

function onID3(event:Event) {
    for(var i in sound.id3)
        trace('prop: ' + i + ' value: '  + sound.id3[i]);
}

For more info, you might find the mp3infoutil library handy.

HTH, George

Upvotes: 3

Related Questions