无法在Android模拟器使用MediaRecorder。是存储位置错了吗? [英] Can not use MediaRecorder on Android Emulator. Is the storage location wrong?

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

问题描述

我想使用Android模拟器录制声音。我知道这个问题是流行在互联网上,我查了很多帖子,似乎只有一个人succeded:<一href=\"http://stackoverflow.com/questions/5254994/can-the-android-emulator-record-and-play-back-audio-using-pc-hardware/6972022#6972022\">Can Android模拟器记录和使用PC硬件播放音频?。 (它认为他用


  

文件fTmFile;与其使用字符串fTmpFile;


我也尝试过)。而继菲利普的意见,并在官方网站的教程 http://developer.android。 COM /引导/主题/媒体/音频capture.html 以及其他资源,我仍然无法录制。我的应用程序在行抛出异常:

  fMediaRecorder prepare()。

更exactley,这是我第一次得到:


  

W / System.err的(1042):java.io.FileNotFoundException:/mnt/sdcard/audiorecordtest.3gp(拒绝)


这让我觉得是有毛病的存储位置,因为即使我说'支持SD卡'属性与大小为256 MIB模拟器,我不能够存取权限的,而且我可以在模拟器中看到信息:您的手机没有插入SD卡当我去音乐

我添加了音频记录和外部存储权限,在AndroidManifest.xml和音频(记录回放+)硬件设置在Win 7模拟器2.3.3是我的应用程序,我的方式存储在文件中的任何错误或者是其他东西?请,如果任何人有任何想法随时分享,这将是AP preciated。

下面是完整的源代码code:

 进口的java.io.File;
进口java.io.FileDescriptor中;
进口java.io.IOException异常;
进口android.app.Activity;
进口android.media.MediaRecorder;
进口android.os.Bundle;
进口android.os.Environment;
进口android.util.Log;
进口android.view.View;
进口android.widget.Button;
进口android.widget.Toast;公共类RecordSoundActivity延伸活动{  私人MediaRecorder fMediaRecorder = NULL;
  私人按钮btnrecord;
  私人按钮btnstop;
  串fTmpFile;  公共RecordSoundActivity(){    fTmpFile = Environment.getExternalStorageDirectory()的getPath()。
    fTmpFile + =/audiorecordtest.3gp;
  }  / **当第一次创建活动调用。 * /
  @覆盖
  公共无效的onCreate(捆绑savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main);    btnrecord =(按钮)findViewById(R.id.button1);
    btnstop =(按钮)findViewById(R.id.button2);    btnrecord.setOnClickListener(新View.OnClickListener(){      @覆盖
      公共无效的onClick(视图v){
        // TODO自动生成方法存根
        Toast.makeText(RecordSoundActivity.this,记录......,Toast.LENGTH_LONG).show();
        记录();
      }
    });    btnstop.setOnClickListener(新View.OnClickListener(){      @覆盖
      公共无效的onClick(视图v){
        // TODO自动生成方法存根
        fMediaRecorder.stop();
        fMediaRecorder.release();
      }
    });
  }  公共无效记录(){
    fMediaRecorder =新MediaRecorder();
    fMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    fMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    fMediaRecorder.setAudioEn codeR(MediaRecorder.AudioEn coder.AMR_NB);    fMediaRecorder.setAudioChannels(1);
    fMediaRecorder.setAudioSamplingRate(8000);    fMediaRecorder.setOutputFile(fTmpFile);    尝试{
      fMediaRecorder prepare()。
    }赶上(IOException异常五){
      // TODO:处理异常
      e.printStackTrace();
    }
    尝试{
      fMediaRecorder.start();
    }赶上(IllegalStateException异常五){
      // TODO:处理异常
      e.printStackTrace();
    }    //fMediaRecorder.stop();
    //fMediaRecorder.release();
  }
}


解决方案

尝试,看看它是否适用于Android 4.0的。我知道我有相机的一些问题在模拟器,在低版本的(低于4.0),它只是不会承认我的笔记本电脑的摄像头。但是,当我试图在4.0,当AVD被装入一个弹出消息来了,问我是否想将摄像头连接到AVD,一旦我同意了它的工作。

在SO问这个问题太,摄像机,并改变AVD版本4.0的另一个海报也帮助他。

也许它同样为录音也一样,都是外部硬件为典型的PC。

I'm trying to record sound using Android Emulator. I know that this question is popular over the internet, I checked many posts, it seems that only one person succeded: Can the Android emulator record and play back audio using pc hardware?. (it think he used

File fTmFile; insteadof String fTmpFile;

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:

W/System.err(1042): java.io.FileNotFoundException: /mnt/sdcard/audiorecordtest.3gp (Permission denied)

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。是存储位置错了吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆