![](/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.