![](/img/trans.png)
[英]Android Studio: How to write a ringtone / notification / alarm audio file to storage and see it in the settings
[英]Write audio file to folder python in android studio
我想錄制音頻 3gp 並將其保存到 app/src/main/python 文件夾,以使用此文件處理 python 代碼。 但是當我用上面的路徑保存文件時,python目錄下沒有這個文件。 我應該怎么辦?
這是我的代碼記錄 3gp 文件
String path = "app/src/main/python/myrecording.3gp";
MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setMaxDuration(1000);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setOutputFile(path);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
try {
recorder.prepare();
recorder.start();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
您實際上需要先創建文件才能保存到它。 我知道這聽起來很奇怪,因為某些 IDE 出於某種原因規避了這一點,而 Android Studio 沒有(顯然),但我在我的設備上也注意到,當我導出應用程序時它通常不會自動執行此操作。
可以在此處找到有關該方法的信息: https://docs.oracle.com/javase/7/docs/api/java/io/File.html#createNewFile()
如果這沒有幫助,那么還請提供應用程序給您的完整錯誤。 堆棧跟蹤通常充滿與已發生錯誤有關的有價值信息。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.