Copy link to clipboard
Copied
hey all
i am having a lot of annoying problems with recording microphone audio and playing it back on the iPhone (same app works flawlessly on desktop and android)
has any of you successfully done that?
Saar
ok i have some answers
Divij Kumar, thanx for the how-to, but i never got to packaging your swf since compiling my own project with "Deployment - Apple App Store" instead of "Quick publishing for device debugging" did the trick.
The app then worked fine.
the quick publishing was the problem, at least in my case
THANX ALL
btw, the recording starts a bit late on my iPhone 3Gs - but this is the iOS's fault - i checked and the built-in app "Voice Memos" is also late. I need in my app instant recording so
...Copy link to clipboard
Copied
Can you specify what problem you are exactly facing so that we can help you around that.
Copy link to clipboard
Copied
@Varun Bhatia,
yes i can
my simple recording test app works great on the desktop and on Android.
on the other hand, on ios (iPhone 3gs, latest os) i sometimes hear nothing on playback, sometimes just the end of the recording, sometimes the playback is stuttering.
thanx,
Saar
i am using flash pro cs5.5 overlayed with the AIR 3 sdk.
the FLA contains two movieclips on stage named "recorder" and "player". they act as buttons. all the code is in the document class:
package {
import flash.display.Sprite;
import flash.media.Microphone;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.events.MouseEvent;
import flash.events.SampleDataEvent;
import flash.utils.ByteArray;
import flash.events.Event;
import flash.media.SoundMixer;
import flash.media.AudioPlaybackMode;
public class RecTest extends Sprite {
var mic:Microphone;
var s:Sound;
var sc:SoundChannel;
var nowRecording:Boolean = false;
var nowPlaying:Boolean = false;
var recordedBytes:ByteArray;
public function RecTest() {
SoundMixer.audioPlaybackMode = AudioPlaybackMode.MEDIA;
mic = Microphone.getMicrophone();
mic.rate = 44;
mic.gain = 70;
mic.setSilenceLevel(0);
s = new Sound();
recordedBytes = new ByteArray();
recorder.addEventListener(MouseEvent.CLICK, record);
player.addEventListener(MouseEvent.CLICK, playBack);
}
function record(e:MouseEvent) {
if (!nowRecording) {
trace("recording");
recordedBytes.clear();
mic.addEventListener(SampleDataEvent.SAMPLE_DATA, getMicAudio);
nowRecording = true;
} else {
trace("recording stopped");
mic.removeEventListener(SampleDataEvent.SAMPLE_DATA, getMicAudio);
nowRecording = false;
}
}
function getMicAudio(e:SampleDataEvent) {
recordedBytes.writeBytes(e.data);
}
function playBack(e:MouseEvent) {
if (!nowPlaying) {
trace("playing");
recordedBytes.position = 0;
s.addEventListener(SampleDataEvent.SAMPLE_DATA, playAudio);
sc = s.play();
sc.addEventListener(Event.SOUND_COMPLETE, stopPlayback, false, 0, true);
nowPlaying = true;
} else {
sc.stop();
stopPlayback();
}
}
function stopPlayback(e:Event=null) {
trace("playing stopped");
s.removeEventListener(SampleDataEvent.SAMPLE_DATA, playAudio);
nowPlaying = false;
}
function playAudio(e:SampleDataEvent) {
for (var i:int = 0; i < 8092 && recordedBytes.bytesAvailable > 0; i++) {
var sample:Number = recordedBytes.readFloat();
e.data.writeFloat(sample);
e.data.writeFloat(sample);
}
}
}
}
Copy link to clipboard
Copied
@Varun Bhatia,
i have some new info
deactivating the app manually and reactivating it again before playback makes most problems go away. (pressing the hardware iPhone button and then pressing the app icon to reactivate)
this feels like a problem AIR has with acquistioning sound channels from the iOS
Copy link to clipboard
Copied
Saariko,
I've not been able to reproduce the problem, I used your code only.
Could you please tell us step by step what exactly you do to see problem reproducing.
I mean what button you press(recorder or player) first after launch, then you press recorder button again or you press player button, then what yo do next..etc.
What I did is as following.
I launched the app, pressed recorder button, recorded some sound, pressed recorder button to stop recording, pressed player button and it played the recording, I did not observe any stuttering here.
You can try with the swf/xml that I've attached.
Also, which device and OS version you're on, do you have many other applications running in background?
Thanks for your support.
-Pahup
Copy link to clipboard
Copied
the steps you took are correct. i have done the same.
to be sure, i closed ALL apps on my iPhone except for my app. the problem remains.
i am using an iPhone 3Gs running 4.3.5
i will be able to test your swf and also test on other iOS devices only later. i will let u know
thanx a lot!
Copy link to clipboard
Copied
Saariko,
When you package the IPA using the swf and app.xml provided by Pahup, please try the "Deployment- Apple App Store" settings. These are present under "AIR for iOS Settings" -> "Deployment (tab)" -> "Deployment - Apple App Store".
Incase you are using ADT with command-line options then please use target as "ipa-app-store". There are known performance limitations of the fast packaging mode and this may be the cause of the incomplete audio that you may be hearing.
Thanks
Divij
(AIR Engineering)
Copy link to clipboard
Copied
how do i package a SWF into an IPA?
i only know how to compile an open FLA+as3 script to an IPA...
thnx
Copy link to clipboard
Copied
In the installation directory for Flash Pro or Flash Builder you would find the AIR sdk which would contain an executable "adt" in the bin directory.
You may use the following command:
adt -package -target ipa-app-store -provisioning-profile <path_to_your_provisioning_profile> -storetype pkcs12 -keystore <path_to_the_associated_keystore> -storepass <password> soundIOS.ipa soundIOS-app.xml soundIOS.swf
For a complete set of options avalible for use in ADT, use
adt -help
Copy link to clipboard
Copied
ok i have some answers
Divij Kumar, thanx for the how-to, but i never got to packaging your swf since compiling my own project with "Deployment - Apple App Store" instead of "Quick publishing for device debugging" did the trick.
The app then worked fine.
the quick publishing was the problem, at least in my case
THANX ALL
btw, the recording starts a bit late on my iPhone 3Gs - but this is the iOS's fault - i checked and the built-in app "Voice Memos" is also late. I need in my app instant recording so I have a constant buffer recording and i use the buttons to mark in and out points instead of adding and removing SampleEvents listeners like we all did here.
cheers