3

NOTE: I have seen the other question in Error #2084-The AMF Encoding of the arguments cannot exceed 40K my problem is different. My array IS NOT 0 and it is less than 40960.

My code is a simple one. I got this mp3 recording fla from this link: http://www.jordansthings.com/blog/?p=5 It uses the shinemp3 encoder.

I just wanted to play the recorded sound rather than saving it. So I added the following to the button that saves the recorded file:

private function onWavClick(e:MouseEvent)
    {           
        // WRITE ID3 TAGS
        var sba:ByteArray = mp3Encoder.mp3Data;
        sba.position =  sba.length - 128
        sba.writeMultiByte("TAG", "iso-8859-1");
        sba.writeMultiByte("Microphone Test 1-2, 1-2      "+String.fromCharCode(0), "iso-8859-1");  // Title
        sba.writeMultiByte("jordansthings                 "+String.fromCharCode(0), "iso-8859-1");  // Artist           
        sba.writeMultiByte("Jordan's Thingz Bop Volume 1  "+String.fromCharCode(0), "iso-8859-1");  // Album        
        sba.writeMultiByte("2010" + String.fromCharCode(0), "iso-8859-1");                          // Year
        sba.writeMultiByte("www.jordansthings.com         " + String.fromCharCode(0), "iso-8859-1");// comments
        sba.writeByte(57);                                                                      

        //new FileReference().save(sba, "FlashMicrophoneTest.mp3") // this saves the file. I don't need it.
        // my addition
        var snd:Sound = new Sound();
        var channel:SoundChannel = new SoundChannel();
        trace(sba.length);
        snd.loadCompressedDataFromByteArray(sba,sba.length);

        channel = snd.play();
    }

Moreover: even if this works... I cannot load an array larger than 40K???

Community
  • 1
  • 1
himura
  • 1,555
  • 3
  • 19
  • 30

2 Answers2

3

Before calling loadCompressedDataFromByteArray, you should set the position of your ByteArray to 0. For example:

sba.position = 0;
snd.loadCompressedDataFromByteArray(sba,sba.length);

I noticed that in my application the bytesAvailable on the ByteArray was 0. This was because the position on the ByteArray was at the end of the ByteArray. The error message is confusing because it says you are exceeding 40K while you are not. It should be saying that there is nothing to load from the ByteArray.

Also, I can confirm that I can load ByteArrays that are larger than 40K. I tested with 126KB mp3 ByteArray.

Scott
  • 3,736
  • 2
  • 26
  • 44
0

In my case the problem was not the size of the ByteArray I wanted to read. I was reading and playing 30 Mb mp3 files without problem (that's a lot, I know!). The problem was that I was reading the file many times, and after the first time the position of the ByteArray was at the end. So you have to restart to 0 the position any time you want to read that byteArray. For security, I assume it is a good practice.