0

I want to download mp3 file, on mobile device iOs or android, because i dont want to download every time from server. I write simple code, but not work correctly. File size is too big, because is not encode and after save I cant play it again.

Please help and sorry for bad English.

private var sound:Sound;
        public function loadSound(tmpUrl:String):void
        {
            sound = new Sound();

            sound.addEventListener(Event.COMPLETE,onLoadSuccessSound, false, 0, true);
            sound.load(new URLRequest(tmpUrl));
        }
        protected function onLoadSuccessSound(event:Event):void
        {
            var fileData:ByteArray = new ByteArray();
            sound.extract(fileData, sound.bytesTotal);

            var file:File = new File(File.applicationStorageDirectory + "\\ppp.mp3");
            var fs:FileStream = new FileStream();
            fs.open(file, FileMode.WRITE);

            fs.writeBytes(fileData,0,fileData.length);
            fs.close();
        }
petter83
  • 1
  • 1
  • I think where you do sound.extract it's decompressing the mp3 into the "raw" audio wave data which means it's the decompressed/decoded version of the mp3. My guess is you would want to just use a Loader or something like that to get the mp3 by itself. I assume you could download the file using a Loader then use an instance of the Sound class to load that local file and play it. – shaunhusain Jun 14 '12 at 23:27

1 Answers1

0

Basically answer is to use URLStream and FileStream.

Question is pretty widespread and covered, for example, here Download a file with Adobe AIR and AS3: URLStream saving files to desktop?

Community
  • 1
  • 1
average dev
  • 1,128
  • 7
  • 22