Skip to main content
Participant
June 8, 2011
Question

Save a sound iOS?

  • June 8, 2011
  • 2 replies
  • 759 views

Hi,

I want to save a sound file to an iOS device that is created with the iOS device (its a byte array but I am going to convert it to MP3), could someone point me in the right direction to do this?

Thanks!

This topic has been closed for replies.

2 replies

relaxatraja
Inspiring
June 9, 2011

http://blancer.com/tutorials/105750/create-a-useful-audio-recorder-app-in-actionscript-3/

June 8, 2011

You can definitely save to your app storage directory, but i don't think you can save to the ios sounds folder (but i could be wrong).  YOu will need to import a wav or mp3 converter, and you need air 2.6+, but these are essentially the functions i use:

private function startMicRecording(evt:MouseEvent):void
        {
            log("Sound Button Pressed");
            log(Microphone.isSupported);
            if(Microphone.isSupported){
                stop_sound_btn.visible = true;
                sound_btn.visible = false;
                sound_btn.removeEventListener(MouseEvent.CLICK, startMicRecording);
                stop_sound_btn.addEventListener(MouseEvent.CLICK, stopSoundRecording);
                log("MIC DETECTED: ");
                //waveEncoder = new WaveEncoder();
                recorder = new MicRecorder(new WaveEncoder);
                recorder.addEventListener(Event.COMPLETE, recordComplete);
                recorder.record();
            }else{
                log("MIC NOT DETECTED");
            }
           
        }
           
        private function stopSoundRecording(evt:MouseEvent):void{
            sound_btn.visible = true;
            stop_sound_btn.visible = false;
            stop_sound_btn.removeEventListener(MouseEvent.CLICK, stopSoundRecording);
            sound_btn.addEventListener(MouseEvent.CLICK, startMicRecording);
            log("Recording Stopped");
            recorder.stop(); //Stop recording
            mic.setLoopBack(false);   
        }

           
        private function recordComplete(e:Event):void
        {
            log("RECORD COMPLETE");
            saveWav();
        }
        private function stopRecord():void
        {
            soundO = new ByteArray();
            soundBytes.position = 0;
            soundO.length=0
            soundO.writeBytes(soundBytes);
            soundO.position = 0;
            soundBytes.length=0;
           
            saveWav();
        }
       
        private function saveWav():void{
           
            var rand:Number = Math.round(Math.random() * 100000);
            var randString = rand.toString();
            log("RANDOM: " + randString);
            temp = new File;
            temp = File.applicationStorageDirectory.resolvePath(randString + "-submission.wav");
            fs = new FileStream();
            fs.addEventListener(Event.COMPLETE, fileSaved);
            fs.addEventListener(IOErrorEvent.IO_ERROR, traceError);
            fs.addEventListener(ProgressEvent.PROGRESS, streamProgress);
            fs.openAsync(temp, FileMode.UPDATE);
            fs.writeBytes(recorder.output);
           
            timer = new Timer(1500, 6);
            timer.addEventListener(TimerEvent.TIMER, onTimer);
        }