在网上搜索后,我找不到从服务器下载mp3的方法,将其保存在本地存储(iPad)中,然后加载并播放它,而不是将其转换为byteArray,将其保存为.mp3然后加载它并将其读回mp3以便能够在Flash应用程序中播放它。
问题是,虽然这种方法工作正常,但保存在本地存储中的未压缩文件(byteArray 格式)太重,我怀疑该应用程序正在浪费内存。
我的问题是,是否有任何形式的直接保存mp3,无需任何转换,就像正确播放的mp3一样?我不能从FileReference使用像download()或save()这样的方法。
非常感谢!!
解决方案!!(完美工作):
我继续在网上寻找一种方法,一些论坛给了我一个线索,让我做我正在搜索的呜呜声。这终于很简单了,但我花了将近 2 周的时间才找到它......这是我的代码:
var queue:LoaderMax = new LoaderMax({name:"mainQueue", onProgress:progressHandler, onComplete:completeHandler, onError:errorHandler});
queue.append( new DataLoader("http://" + **url**, {name:**"example.mp3"**format:"binay"}));
queue.load();
// Complete Event:
private function completeHandler():void {
var file:File = new File(**your location**); // appData
var fr:FileStream = new FileStream();
fr.open(file.resolvePath(nameIn), FileMode.WRITE);
fr.writeObject(LoaderMax.getContent("example.mp3"));
fr.close();
fr = null;
// Now the mp3 is saved in local storage, we load it as Sound object so we can play it.
var loader:MP3Loader;
loader = new MP3Loader(**your location**, {autoPlay:false}) ;
loader.addEventListener(Event.COMPLETE, function():Sound {
loader.content.play(); // This line is the only one not checked, but I am completely sure you can do something like this to play the sound. For example, I introduce the loader.content in a Array of Sound and later I am capable to play any sound I want.
loader.dispose(true); // This is very important to free memory. You should do the same thing with queue when all items are downloaded.
});
loader.load();
}
我希望这对很多人有所帮助!!