【问题标题】:can't find audio file after recording录制后找不到音频文件
【发布时间】:2016-06-21 11:28:54
【问题描述】:

我在 android studio 中创建了一个录音机,但我在手机上找不到录制的文件。通常我打算将其附加到将要发送的电子邮件中,但我无法在手机上找到它以将其添加为附件。这是我写在下面的代码

   private String outputFile = null;

   private MediaRecorder mRecorder;

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);


    outputFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/recording.3gpp";
    }




     public void startRecording() throws Exception {



    if(mRecorder!=null){
        mRecorder.release();
    }

    File fileOut = new File(outputFile);

    if(fileOut!=null){
        fileOut.delete();
    }


    mRecorder = new MediaRecorder();
    mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    mRecorder.setOutputFile(outputFile);
    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);


        mRecorder.prepare();

    mRecorder.start();
}





public void stopRecording() {

    if(mRecorder != null) {
        mRecorder.stop();
        mRecorder.release();
    }
}

public void record(){



    new CountDownTimer(10000, 10000) { // 5000 = 5 sec

        public void onTick(long millisUntilFinished) {
            try {
                startRecording();
            } catch (Exception e) {
                e.printStackTrace();
            }
            Toast.makeText(HomeActivity.this, R.string.record_audio, Toast.LENGTH_LONG).show();
        }

        public void onFinish() {
            stopRecording();
            mProgressDialog.dismiss();
            Toast.makeText(HomeActivity.this, R.string.record_saved, Toast.LENGTH_LONG).show();
        }
    }.start();


}

【问题讨论】:

  • 你添加权限了吗?
  • 我有,添加用于录制和外部存储
  • 如果你在API23及以上开发,你必须在运行时请求权限。此外,如果您的应用低于 API23,但在 API23 及以上的设备上运行,您需要调整您的应用并请求该权限,因为这些权限可能不会自动添加。
  • 目前在 22 上运行以进行测试
  • 两件事:首先,您要删除一个不为空的文件?我猜你想删除之前创建的文件?所以必须调用 if(fileOut.exists()) 而不是 if(fileOut!=null) 。第二:为什么你在倒数计时器中设置这个?你在哪里开始计时器?你无处可调用record()startRecording() 方法.....

标签: android avaudiofile


【解决方案1】:

您的存储可能未安装。我尤其在 CyanogenMod 系统上遇到了默认情况下未安装 sotrages 的问题。只需调用以下命令即可确保已安装存储:

    boolean isMountend = Environment.getExternalStorageState().
equals(android.os.Environment.MEDIA_MOUNT‌​ED); 

【讨论】:

    【解决方案2】:

    当您通过电缆连接复制它们时,它们不会显示。您需要通过 WiFi 连接,打开手机上的录音,然后点击右上角的选项。将有一个选项可以将其上传到 Google Drive。将其上传到您的帐户后,将其下载到您的桌面驱动器。

    【讨论】:

      猜你喜欢
      • 2013-05-01
      • 2018-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多