AS3 mp3导入错误:参数的AMF编码不能超过40K



注意:我在错误#2084中看到了另一个问题。参数的AMF编码不能超过40K我的问题不一样。我的数组不是0,并且小于40960。

我的代码很简单。我从这个链接得到了这个mp3录音fla:http://www.jordansthings.com/blog/?p=5它使用shinenp3编码器。

我只是想播放录制的声音,而不是保存它。所以我在保存录制文件的按钮上添加了以下内容:

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();
    }

此外:即使这有效。。。我无法加载大于40K的数组???

在调用loadCompressedDataFromByteArray之前,您应该将ByteArray的位置设置为0。例如:

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

我注意到,在我的应用程序中,ByteArray上的bytesAvailable为0。这是因为ByteArray上的位置位于ByteArray的末尾。错误消息令人困惑,因为它说你超过了4万,而你没有。应该说,没有什么可以从ByteArray加载的。

此外,我可以确认我可以加载大于40K的ByteArrays。我用126KB的mp3 ByteArray进行了测试。

在我的案例中,问题不在于我想要读取的ByteArray的大小。我一直在阅读和播放30 Mb的mp3文件,没有问题(我知道这是很多!)。问题是我读了很多次这个文件,第一次之后ByteArray的位置就在最后了。因此,每当您想读取该字节数组时,都必须重新启动到0位置。为了安全起见,我认为这是一个很好的做法。

最新更新