In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

How to check if URL is not MP3

Get Adobe Flash player
by makc3d 10 Mar 2014
package {
    import com.actionscriptbible.*;
    import flash.events.*;
    import flash.media.*;
    import flash.net.*;
    import flash.utils.*;
    public class InvalidSoundURL extends Example {
        public function InvalidSoundURL() {
            // write as3 code here..
            var sound:Sound = new Sound();
            sound.addEventListener(IOErrorEvent.IO_ERROR, onSoundError);
            sound.addEventListener(Event.COMPLETE, onSoundLoaded);
            sound.load(new URLRequest("http://google.com/"), new SoundLoaderContext(777, true));
        }

	private function onSoundError(e:IOErrorEvent):void {
		(e.target as EventDispatcher).removeEventListener(IOErrorEvent.IO_ERROR, onSoundError);

		if (e.errorID == 2124) {
			trace("this should happen in theory, but does not in practice");
		}
	}

	private function onSoundLoaded(e:Event):void {
		(e.target as EventDispatcher).removeEventListener(Event.COMPLETE, onSoundLoaded);

		var s:Sound = e.target as Sound;
		if (s.isBuffering && (s.extract(new ByteArray(), 1, 0) < 1)) {
			trace("here is how to know that this URL was not MP3");
		}
	}
    }
}