Android MediaRecorder - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android MediaRecorder class.

This code example shows how to use the following methods:prepare, setAudioEncoder, setAudioSource, setOutputFile, setOutputFormat
	}	 
	 
	protected void startRecording(String file){
		if (!isRecording){
			saveFile=file;
			recorder = new MediaRecorder();
			recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
			recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
			recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
			recorder.setOutputFile(this.recording);
			try { 
				recorder.prepare();
			} catch (IllegalStateException e) {
				// TODO Auto-generated catch block 
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block 
				e.printStackTrace();
			} 
			isRecording = true;

10
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:prepare, setAudioEncoder, setAudioSource, setOutputFile, setOutputFormat
	 
	// Methods 
	@Kroll.method 
	public void start() { 
		if (recorder == null) {
			recorder = new MediaRecorder();
			recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
			recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
			recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
			recorder.setOutputFile("/dev/null");
			try { 
				recorder.prepare();
				recorder.start();
			} catch (IOException e) {
			} 
 
		} 
	} 
	 
	@Kroll.method 
10
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:prepare, setAudioChannels, setAudioEncoder, setAudioEncodingBitRate, setAudioSource
      File output=
          new File(
                   Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
                   BASENAME);
 
      recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
      recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
      recorder.setOutputFile(output.getAbsolutePath());
 
      if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD_MR1) {
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
        recorder.setAudioEncodingBitRate(160 * 1024);
      } 
      else { 
        recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
      } 
 
      recorder.setAudioChannels(2);
 
      try { 

8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:prepare, reset, setAudioEncoder, setAudioSource, setOutputFile
		File directory = soundFile.getParentFile();
		if (!directory.exists() && !directory.mkdirs()) {
			throw new IOException("Path to file could not be created.");
		} 
 
		recorder.reset();
		recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
		recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
		recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
		recorder.setOutputFile(path);
		recorder.prepare();
		recorder.start();
		isRecording = true;
	} 
 
	public void stop() throws IOException { 
		recorder.stop();
		recorder.reset();
		recorder.release();
		isRecording = false;
8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:prepare, setAudioEncoder, setAudioSource, setOutputFile, setOutputFormat
			audiofile = File.createTempFile("sound", ".3gp", sampleDir);
		} catch (IOException e) {
			Log.e(TAG, "sdcard access error");
			return; 
		} 
		recorder = new MediaRecorder();
		recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
		recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
		recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
		recorder.setOutputFile(audiofile.getAbsolutePath());
		recorder.prepare();
		recorder.start();
	} 
 
	public void stopRecording(View view) {
		startButton.setEnabled(true);
		stopButton.setEnabled(false);
		recorder.stop();
		recorder.release();
		addRecordingToMediaLibrary(); 
10
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:prepare, setAudioEncoder, setAudioSource, setOutputFile, setOutputFormat
    if (!directory.exists() && !directory.mkdirs()) {
      throw new IOException("Path to file could not be created.");
    } 
     
    setPath(path);
    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
    recorder.setOutputFile(path);
    recorder.prepare();
    recorder.start();
  } 
   
  public void setPath(String s) {
      try { 
          File f = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/rpath.txt");
          f.delete();
          f.createNewFile();
          FileOutputStream fOut = new FileOutputStream(f);
          OutputStreamWriter osw = new OutputStreamWriter(fOut); 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:prepare, setAudioEncoder, setAudioSource, setOutputFile, setOutputFormat
	 *  
	 * @throws IllegalStateException 
	 * @throws IOException 
	 */ 
	public void registerCapture() throws IllegalStateException, IOException { 
		recorder = new MediaRecorder();
		recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
		recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
		recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
		recorder.setOutputFile(filePath);
		recorder.prepare();
	} 
 
	/** 
	 * Call this to start capture 
	 */ 
	public void startCapture() { 
		recorder.start();
	} 
 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:
  private MediaRecorder mediaRecorder;
  private ShadowMediaRecorder shadowMediaRecorder;
 
  @Before 
  public void setUp() throws Exception { 
    mediaRecorder = new MediaRecorder();
    shadowMediaRecorder = Robolectric.shadowOf(mediaRecorder);
  } 
 
  @Test 
  public void testAudioChannels() throws Exception { 
    assertThat(shadowMediaRecorder.getAudioChannels()).isNotEqualTo(2);
    mediaRecorder.setAudioChannels(2);
    assertThat(shadowMediaRecorder.getAudioChannels()).isEqualTo(2);
  } 
 
  @Test 
  public void testAudioEncoder() throws Exception { 
    assertThat(shadowMediaRecorder.getAudioEncoder()).isNotEqualTo(MediaRecorder.AudioEncoder.AMR_NB);
    assertThat(shadowMediaRecorder.getState()).isNotEqualTo(ShadowMediaRecorder.STATE_DATA_SOURCE_CONFIGURED);
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:setOnErrorListener, setOnInfoListener
 
  @Override 
  public void onResume() { 
    super.onResume(); 
 
    recorder=new MediaRecorder();
    recorder.setOnErrorListener(this);
    recorder.setOnInfoListener(this);
  } 
 
  @Override 
  public void onPause() { 
    recorder.release();
    recorder=null;
 
    super.onPause(); 
  } 
 
  @Override 
  public void onCheckedChanged(CompoundButton buttonView,
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:prepare, setAudioEncoder, setAudioSource, setOutputFile, setOutputFormat
        // ファイル名 
        String name = System.currentTimeMillis() + ".3gp";
        // 出力ファイルのパス 
        String path = new File(appDir, name).getAbsolutePath();
 
        mRecorder = new MediaRecorder();
        // 入力ソースにマイクを指定 
        mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        // 出力フォーマットに3gpを指定 
        mRecorder.setOutputFormat(
                MediaRecorder.OutputFormat.THREE_GPP);
        // 音声エンコーダにAMRを指定 
        mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
        // 出力ファイルのパスを指定 
        mRecorder.setOutputFile(path);
        try { 
            // 準備して 
            mRecorder.prepare();
            // 録音スタート! 
            mRecorder.start();

8
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Android MediaRecorder Questions & Answers:

Other Android MediaRecorder Examples

18:	public class SoundRecordingActivity extends Activity {
19:	
20:	  MediaRecorder recorder;
21:	  File audiofile = null;
22:	  private static final String TAG = "SoundRecordingActivity";
-
44:	      return;
45:	    }
46:	    recorder = new MediaRecorder();
47:	    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
48:	    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);

Read More

See Code Examples for Android MediaRecorder Methods: