Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Does anyone know when Titanium will support Android audio recording?

Spent an hour trying to get audio recording to work on Android then realized it was not yet supported. However, I need it for the app I am working on and would hate to start over on iPhone. Any idea if this will be supported in the next release?

— asked August 28th 2010 by Doug Kersten
  • android
  • audio
  • recording
1 Comment
  • Go to vocalrank.com. That android audio recording module picks up where Codeboxed stopped. It works with TiStudio 3.0, and targets Android SDK 10. There's a sample apk available for download and more info about the Android audio recorder module.

    — commented February 12th 2013 by Eric Dean

3 Answers

  • I just spent a few hours also discovering that the promise of a cross-platform API has not quite been realized yet on Titanium. Looking at Jeff's blog, doesn't look like it will be included in release 1.5 which will be available in a couple weeks. Shoot! I need this functionality.

    — answered September 5th 2010 by Alex Shah
    permalink
    0 Comments
  • 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.

    — answered August 4th 2011 by Alexandru Budin
    permalink
    3 Comments
    • This doesn't work in the current version of Titanium.

      — commented May 4th 2012 by C Lee
    • We are working on fixing this right now.

      — commented May 4th 2012 by Alexandru Budin
    • what is version??
      i use Ti.sdk 3.0.0v,
      but. its not work ..

      and 2013/1m/ now, www.codeboxed.com is not running

      — commented January 4th 2013 by Seungik Kim
  • Hi ,

    You can try it with this code

    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();

    — answered May 9th 2012 by Harsh Punnoose
    permalink
    1 Comment
    • Thanks for your contribution Harsh. Looks like your sample works on TiSDK 3.1.0.GA & Android 2.3.5 Razr Device.

      Posting snippet formatted:

      var RECORD_SOUND_ACTION = "android.provider.MediaStore.RECORD_SOUND";
      var soundUri = null;
      // Will be set as a result of recording action.
      
      var win = Ti.UI.createWindow({
      backgroundColor: "red"
      });
      
      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);
      
      var intent = Titanium.Android.createIntent({
              action : RECORD_SOUND_ACTION
          });
      
      recordButton.addEventListener('click', function() {
          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();
      

      — commented May 1st 2013 by Eduardo Gomez
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.