Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i enable media option on android emulator with command line

in my app i am recording speech so that i need to set up my emulator able to record speech. i have searched in the google i got some solution that is need to start emulator by manually with media option. i use the following cmd but i got error.

emulator -avd Test -audio-in MIC

i am using Android 2.2(Api 2.2) on windows 7. How do i enable MIC option on my emulator. please help me.

I got the following error:

>emulator -avd Test -audio-in MIC

>unknown option: -audio-in

please use -help for a list of valid options

like image 272
M.A.Murali Avatar asked Apr 07 '12 07:04

M.A.Murali


People also ask

How do I open an Android Emulator from the command-line?

Starting the emulator Use the emulator command to start the emulator, as an alternative to running your project or starting it through the AVD Manager. Here's the basic command-line syntax for starting a virtual device from a terminal prompt: emulator -avd avd_name [ {- option [ value ]} … ]


1 Answers

Try to use this example:

package com.benmccann.android.hello;

import java.io.File;
import java.io.IOException;

import android.media.MediaRecorder;
import android.os.Environment;

/**
 * @author <a href="http://www.benmccann.com">Ben McCann</a>
*/

public class AudioRecorder {

final MediaRecorder recorder = new MediaRecorder();
final String path;

/**
* Creates a new audio recording at the given path (relative to root of SD card).
*/
public AudioRecorder(String path) {
this.path = sanitizePath(path);
}

private String sanitizePath(String path) {
  if (!path.startsWith("/")) {
  path = "/" + path;
 }
 if (!path.contains(".")) {
  path += ".3gp";
 }
 return Environment.getExternalStorageDirectory().getAbsolutePath() + path;
}

/**
 * Starts a new recording.
*/
public void start() throws IOException {
  String state = android.os.Environment.getExternalStorageState();
  if(!state.equals(android.os.Environment.MEDIA_MOUNTED))  {
    throw new IOException("SD Card is not mounted.  It is " + state + ".");
 }

 // make sure the directory we plan to store the recording in exists
 File directory = new File(path).getParentFile();
  if (!directory.exists() && !directory.mkdirs()) {
  throw new IOException("Path to file could not be created.");
 }

 recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
 recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
 recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
 recorder.setOutputFile(path);
 recorder.prepare();
 recorder.start();
}

/**
* Stops a recording that has been previously started.
*/
public void stop() throws IOException {
recorder.stop();
recorder.release();
}

}

Hope this help you. Let us know how it goes, or if you need further help.

like image 134
ThreaderSlash Avatar answered Oct 30 '22 04:10

ThreaderSlash