【问题标题】:Android audio captureAndroid 音频捕获
【发布时间】:2014-02-06 03:11:47
【问题描述】:

我正在关注this 文章以在 Android 上捕获音频。我以为这很容易,但有一个问题。代码如下:

    File dir = activity.getDir("recordings", Context.MODE_PRIVATE);
    File file = new File(dir, "testaudio.mpeg4");

    FileUtil fileUtil = new FileUtil();
    File parent = file.getParentFile();

    if(!parent.exists()){
        Log.i(TAG, "Creating non-existent path:" + parent.getAbsolutePath());
        parent.mkdirs();
    } 

    recorder = new MediaRecorder();
    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);

        try{
            recorder.setOutputFile(file.getAbsolutePath());
            recorder.prepare();
            recorder.start();
        }catch(IOException e){
        //more code
        }

因此,它确实在 /data/data/com.myapp/app_recordings/ 文件夹下创建了一个 testaudio.mpeg4 文件。但是,将文件传输到 Mac(使用 adb pull)后,它无法播放。我在 Mac 上尝试了几种音频格式(例如 MP3、MPEG、3GP 等),但似乎没有任何效果。任何帮助/指导将不胜感激。

【问题讨论】:

    标签: android audio media audio-recording


    【解决方案1】:

    使用这个

    File dir = new File(Environment
                .getExternalStorageDirectory().getAbsolutePath() + "/recording/");
    

    【讨论】:

    • 但是,我不想写入外部存储。 activity.getDir("recordings", Context.MODE_PRIVATE) 让我私下给应用写信。
    【解决方案2】:

    这似乎是 Mac 问题,代码或设备没有问题。我可以听到设备上的音频。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-04-11
      • 1970-01-01
      • 1970-01-01
      • 2017-04-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多