Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to play a zipped wave file in Flash Mobile

I am working on a project in Flash Mobile using ActionScript. I have a zipped wav file that I need to be able to de serialize and play as needed in a Button Press action. Below is the code for zipping the wav file.

                mic.removeEventListener(SampleDataEvent.SAMPLE_DATA, micSampleDataHandler);
                btnRecord.setStyle("icon", recOff);
                sampleCount++;

                // save the raw PCM samples as a bare WAV file
                var wav:ByteArray = new ByteArray();
                var writer:WAVWriter = new WAVWriter();
                writer.numOfChannels = 1;
                writer.sampleBitRate = 16;
                writer.samplingRate = 11025;
                samples.position = 0;
                writer.processSamples(wav, samples, 11025, 1);
                wav.position = 0;

                // zip the WAV file
                var fzip:FZip = new FZip();
                fzip.addFile(name + sampleCount.toString(), wav);
                var zip:ByteArray = new ByteArray();
                fzip.serialize(zip);
                var recSpot:Object = {
                        id: null,
                        audio: zip,
                        name: "New Audio File " + newRecNum,
                        existsdb: "false"
                };
                newRecNum++;
                recordings.addItem(recSpot);
            }

What can I do to play this file, really haven't had to play a zipped file before.

like image 470
yams Avatar asked Oct 02 '22 02:10

yams


1 Answers

I'm not familiar with WAVWriter (which is probably somewhat beside the point), but here's what I do know.

Firstly, because of the nature of a compression, you cannot (as far as I know) play a zipped audio file, period. You will need to unzip it first.

A quick Google search turned up THIS AS3 TUTORIAL on unzipping with FZIP. The example program is using .PNGs, but I would assume you can adjust it to work with the raw .WAV file you zipped earlier. Skip down to Step 5 for the actual code. (You'll need to rewrite it to work with your interface, obviously.)

You won't need the DataProvider variable in step 5, as that is for components, specifically. You'll need to load your data into something else. If your method of playing WAV files is anything like mine (I use the as3WAVSound class), you'll probably want to load the data into a ByteArray and play off of that.

You also probably won't need the for loop he uses in step 10, as your code appears to be creating a ZIP with only one WAV file. That simplifies things considerably.

Anyway, I hope that answers your question!

like image 115
CodeMouse92 Avatar answered Oct 08 '22 05:10

CodeMouse92