是存储位置错了吗

是存储位置错了吗

本文介绍了无法在Android模拟器使用MediaRecorder。是存储位置错了吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Android模拟器录制声音。我知道这个问题是流行在互联网上,我查了很多帖子,似乎只有一个人succeded:Can Android模拟器记录和使用PC硬件播放音频?。 (它认为他用

which i also tried). And following Philip's advice and the official site tutorial http://developer.android.com/guide/topics/media/audio-capture.html and also other resources, I'm still not able to record. My application throws exception at line:

fMediaRecorder.prepare();

more exactley, this is what I first get:

which makes me think is something wrong with the storage location, because even I added 'SD Card Support' property for the emulator with size 256 MiB, I'm not able to acces it, furthermore I can see in the emulator the message: "Your phone does not have a SD Card inserted" when I go to Music.

I added both audio record and external storage permissions, in AndroidManifest.xml and both audio (record+playback) hardware settings to the emulator 2.3.3 on Win 7. Is anything wrong within my app, the way I storage the file or something else? Please, if anybody has any idea feel free to share, it will be appreciated.

Here is the full source code:

import java.io.File;
import java.io.FileDescriptor;
import java.io.IOException;
import android.app.Activity;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.os.Environment;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class RecordSoundActivity extends Activity {

  private MediaRecorder fMediaRecorder = null;
  private Button btnrecord;
  private Button btnstop;
  String fTmpFile;

  public RecordSoundActivity() {

    fTmpFile = Environment.getExternalStorageDirectory().getPath();
    fTmpFile += "/audiorecordtest.3gp";
  }

  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    btnrecord = (Button) findViewById(R.id.button1);
    btnstop = (Button) findViewById(R.id.button2);

    btnrecord.setOnClickListener(new View.OnClickListener() {

      @Override
      public void onClick(View v) {
        // TODO Auto-generated method stub
        Toast.makeText(RecordSoundActivity.this, "Recording...", Toast.LENGTH_LONG).show();
        Recording();
      }
    });

    btnstop.setOnClickListener(new View.OnClickListener() {

      @Override
      public void onClick(View v) {
        // TODO Auto-generated method stub
        fMediaRecorder.stop();
        fMediaRecorder.release();
      }
    });
  }

  public void Recording() {
    fMediaRecorder = new MediaRecorder();
    fMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    fMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    fMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

    fMediaRecorder.setAudioChannels(1);
    fMediaRecorder.setAudioSamplingRate(8000);

    fMediaRecorder.setOutputFile(fTmpFile);

    try {
      fMediaRecorder.prepare();
    } catch (IOException e) {
      // TODO: handle exception
      e.printStackTrace();
    }
    try {
      fMediaRecorder.start();
    } catch (IllegalStateException e) {
      // TODO: handle exception
      e.printStackTrace();
    }

    //fMediaRecorder.stop();
    //fMediaRecorder.release();
  }
}
解决方案

Try and see if it works for Android 4.0. I know I had some issues with the camera in the emulator, in lower version (Lower than 4.0) it just wouldn't recognize my laptop webcam. But when I tried it on 4.0, when the AVD was loading a popup message came and asked me if I want to connect the webcam to the AVD, and once I agreed it worked.

Another poster in SO asked this question too, about the camera, and changing the AVD version to 4.0 did help him.

Maybe its the same for audio recording too, as both are external hardware for the typical PC.

这篇关于无法在Android模拟器使用MediaRecorder。是存储位置错了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 17:05