record Audio using Titanium Framework
Can we record Audio using Titanium Framework? (both Android and iPhone)
18 Answers
-
You can try this code for audio recording
var win = Titanium.UI.createWindow({ title: 'Video Recording from Appcelerator Titanium', backgroundColor: '#fff' }); // const value grabbed from // http://developer.android.com/reference/android/provider/MediaStore.Audio.Media.html#RECORD_SOUND_ACTION var RECORD_SOUND_ACTION = "android.provider.MediaStore.RECORD_SOUND"; var soundUri = null; // Will be set as a result of recording action. var recordButton = Titanium.UI.createButton({ top: 10, left: 10, right: 10, height: 35, title: "Record Audio" }); var labelResultCaption = Titanium.UI.createLabel({ top: 50, left: 10, right: 10, height: 35, visible: false, color: 'yellow' }); var labelResult = Titanium.UI.createLabel({ top: 90, left: 10, right: 10, height: 100, visible: false, backgroundColor: 'white', color: 'black', verticalAlign: 'top' }); var shareButton = Titanium.UI.createButton({ top: 50, left: 10, right: 10, height: 35, title: 'Share Recorded Video', visible: false }); win.add(shareButton); var saveButton = Titanium.UI.createButton({ top: 100, left: 10, right: 10, height: 35, title: 'Save Recorded Video', visible: false }); win.add(saveButton); recordButton.addEventListener('click', function() { var intent = Titanium.Android.createIntent({ action: RECORD_SOUND_ACTION }); Titanium.Android.currentActivity.startActivityForResult(intent, function(e) { if (e.error) { Titanium.UI.createNotification({ duration: Titanium.UI.NOTIFICATION_DURATION_LONG, message: 'Error: ' + e.error }).show(); } else { if (e.resultCode === Titanium.Android.RESULT_OK) { soundUri = e.intent.data; Titanium.UI.createNotification({ duration: Titanium.UI.NOTIFICATION_DURATION_LONG, message: 'Video captured; now share or save it!' }).show(); // note that this isn't a physical file! it's a URI in to the MediaStore. shareButton.visible = true; saveButton.visible = true; } else { Titanium.UI.createNotification({ duration: Titanium.UI.NOTIFICATION_DURATION_LONG, message: 'Canceled/Error? Result code: ' + e.resultCode }).show(); } } }); }); saveButton.addEventListener('click', function() { var source = Titanium.Filesystem.getFile(soundUri); var target = Titanium.Filesystem.getFile('appdata://harsh.amr'); // note: source.exists() will return false, because this is a URI into the MediaStore. // BUT we can still call "copy" to save the data to an actual file source.copy(target.nativePath); Ti.UI.createNotification({ duration: Titanium.UI.NOTIFICATION_DURATION_LONG, message: 'Saved to: ' + target.nativePath }).show(); }); shareButton.addEventListener('click', function() { var intent = Titanium.Android.createIntent({ action: Titanium.Android.ACTION_SEND, type: 'audio/amr' }); intent.putExtraUri(Titanium.Android.EXTRA_STREAM, soundUri); Titanium.Android.currentActivity.startActivity( Titanium.Android.createIntentChooser(intent, 'Send Video via')); }); win.add(recordButton); win.add(labelResultCaption); win.add(labelResult); win.open();
-
Hi Maurice,
All Titanium API methods come from modules, the Titanium platform is formed from a lot of modules written as this one, the only difference is that you don't have to write a REQUIRE statement at the beginning ;)
And lets face it, did you manage to do an app that works on both platforms without using an (ifAndroid) statement?
The two platforms are very different, and the guys from Appcelerator are doing a tremendous job to make as many features as they can to run platform independent.
This is why a lot of us are writing this modules to help everybody out, and take the load from Appcelerator.
We will make this recording module have the same behavior as the iPhone one, but i hope this version of the module will help until then.
Thank you.
-
Yes, it can. Please refer to titanium api to see how to save record audio.
-
There's an audio recording sample in Kitchen Sink, you can check it here.
If you downloaded Kitchen Sink, you can test it under Phone -> Sound -> Recording.
-
Hi Friends,
As of now, it seems that, Audio Recording is supported only for iPhone through Titanium. I found it from this link:
http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Media.AudioRecorder-object.html
I did not receive any answer from the Appcelerator people, so I assume this is the case.
-
I found in documentation that Audio Recording is supported only in iPhone and not Android. There was no example in KitchenSink for Android,but demonstrated for iPhone. So, I consider, it is not supported for Android.
-
any status as to when audio recording will be available for android?
-
Is audio recording supported on Android yet??
-
BUMP!
Come on guys, you can't leave us developers in the cold for so long.
How about a nice reply saying when it's planned for? -
Android recording is supported – see here > http://developer.appcelerator.com/blog/2011/02/launching-activities-and-using-content-uris-in-android.html
The problem for me is Ti currently provides no way (outside of creating a custom Module) to determine the actual file name for the recording from the recording URI.
Why they didn't take the extra step to provide that is puzzling….but I hope it gets addressed pronto!
-
I'm sorry, but that only covers commanding an 'intent' (which uses the most ugly embedded components I have seen on a mobile device btw).
According to Androids docs, it is also possible to use the MediaRecorder class (android.media.MediaRecorder).
Why not plug that into Titanium? It seems very similar to the iPhone's setup.
docs I found:
http://www.brighthub.com/mobile/google-android/articles/40737.aspx
http://www.benmccann.com/dev-blog/android-audio-recording-tutorial/ -
Now recording is possible on Android, natively, without Intents.
We just released the Audio Recorder Titanium Module for Android.
You can see more details on Codeboxed Titanium Audio Recorder Module
Follow us on Twitter: @codeboxed for more updates. -
That was rather quick? Thank you guys for making this possible!
-
Hmmmm….I don't see your docs updated. The Ti.Media.AudioRecorder still shows it's only compatible with idevices:
http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Media.AudioRecorder-object
Also, I have updated your sdk, but after rebuilding my app I still get errors about Ti.Media.createAudioRecorder not being available on Android.
What am I missing here? I surely do hope your addition did not find it's way into some proprietary Android corner of your sdk.
-
Aha, it's a third party module that only works for Android. Hmmm…now wouldn't it be nice if it was plugged onto your Ti.Media.AudioRecorder api.
Please, we all want you to incorporate this solution so we don't have to write code twice, right ppl?
-
Wow, thanks for replying so quickly.
I have to say so far I have only made some demos with titanium without fancy stuff, so yeah, no need yet for ifAndroid logic.
But it's very kool to read you saying this module will be adapted to follow the existing api. I hope it's not too hard.
It would be real nice to have my demo ready with android recording working without too much tweaking. But it's not a must for me right now to support android, as its just a demo.But thanks again!
-
it may be because of your sd card is not detected. you can check your sd card is working properly. try with your default recording application in your device. this code is properly working on my device.
-
Now recording is possible on Android, natively, without Intents.
We just released the Audio Recorder Titanium Module for Android.
You can see more details on Codeboxed Titanium Audio Recorder Module
Follow us on Twitter: @codeboxed for more updates.