2014-02-06 156 views
2

我正在關注this文章以捕獲Android上的音頻。我認爲這很容易,但有一個問題。下面的代碼: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等),但似乎沒有任何工作。任何幫助/指導將不勝感激。

回答

0

使用此

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

但是,我不想寫入外部存儲。 activity.getDir(「recordings」,Context.MODE_PRIVATE)允許我私人寫入應用程序。 – user3277846

0

這似乎是一個Mac的問題,沒有錯的代碼或設備。我可以聽到設備上的音頻。