flash.media.Sound
is a high level class that allows you to play a sound file in one line : new Sound(new URLRequest('your url')).play();
but does not provide public access to the data being loaded
The class will handle streaming for you (more precisely, progressive download)
If you need to access id3 data, just listen the Event.ID3 event:
var sound:Sound = new Sound("http://archive.org/download/testmp3testfile/mpthreetest.mp3");
sound.addEventListener(Event.ID3, onId3);
sound.play();
function onId3(e:Event):void {
var id3:ID3Info = (e.target as Sound).id3;
trace(id3.album, id3.artist, id3.comment, id3.genre,
id3.songName, id3.track, id3.year);
}
If you really need to get the raw first 48 bytes and process them by yourself, but keep in mind you will have to deal with various mp3 formats id3/no id3, and work directly on binary data, instead of letting actionscript do the work for you.
Assuming you don't want to download the mp3 file twice, you can either:
Load the mp3 file as ByteArray with URLLoader, read the 48 bytes manually, and load the Sound instance from memory, thus losing any progressive download ability. :
var l:URLLoader = new URLLoader;
l.dataFormat = URLLoaderDataFormat.BINARY;
l.addEventListener(Event.COMPLETE, onComplete);
l.load(new URLRequest("http://archive.org/download/testmp3testfile/mpthreetest.mp3"));
function onComplete(e:Event):void {
//do whatever you need to do with the binary data (l.data)
// ...
// load sound from memory
new Sound().loadCompressedDataFromByteArray(l.data, l.data.length);
You could also load use the Sound class in the classic way (to allow progressive download), and load independently the first 48 bytes with a URLStream, and close the stream ASAP (only onie packet of network overhead, plus you might get it from cache anyway) :
var s:URLStream = new URLStream;
s.addEventListener(ProgressEvent.PROGRESS, onStreamProgress);
s.load(new URLRequest("http://archive.org/download/testmp3testfile/mpthreetest.mp3"));
function onStreamProgress(e:ProgressEvent):void {
if (s.bytesAvailable >= 48) {
// whatever you need to do with the binary data: s.readByte()...
s.close();
}
}
I'm still curious to know why you would need those 48 bytes ?
EDIT: since the 48 bytes are supposed to be fed to MP3InfoUtil, you don't need to do anything particular, just let the lib do the work :
MP3InfoUtil.addEventListener(MP3InfoEvent.COMPLETE, yourHandler);
MP3InfoUtil.getInfo(yourMp3Url);