【问题标题】:Write audio file to folder python in android studio将音频文件写入android studio中的文件夹python
【发布时间】:2021-11-30 09:25:43
【问题描述】:

我想录制音频 3gp 并将其保存到 app/src/main/python 文件夹,以使用此文件处理 python 代码。但是当我用上面的路径保存文件时,python目录下没有这个文件。我该怎么办?

My picture with this folder

这是我的代码记录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();
    }

【问题讨论】:

    标签: java android record


    【解决方案1】:

    您实际上需要先创建文件才能保存到该文件。我知道这听起来很奇怪,因为某些 IDE 出于某种原因规避了这一点,而 Android Studio 没有(显然),但我也注意到在我的设备上,当我导出应用程序时它通常不会自动执行此操作。

    可以在此处找到有关该方法的信息: https://docs.oracle.com/javase/7/docs/api/java/io/File.html#createNewFile()

    如果这没有帮助,那么还请提供应用程序给您的完整错误。堆栈跟踪通常包含与已发生错误有关的有价值信息。

    【讨论】:

    • 不,它没有给出错误,我可以使用 getExternalFilesDir() 在模拟器中保存和查找文件,但我无法保存到 python 文件夹。
    • 能否提供一段代码,其中 Path 用于指定文件的保存位置?我猜它没有把它保存在你期望的地方。 (例如,它直接将其保存在“App”文件夹中,因为我没有看到上面代码中指定的路径。
    • 对不起,我是安卓新手。我认为路径是src/python/,因为我在gradle文件中使用python.srcDir "src/main/python"?当我将路径用作getExternalFilesDir(null).getAbsolutePath()+"/myrecording.mp3" 时,文件将保存到模拟器中的路径 android/data/com.example.testaudio/files 中。你可以在这张图片中看到link
    • 没问题,这是一个学习的过程。错误时有发生,但熟能生巧。上面的链接也不起作用(我认为文件没有共享)。
    猜你喜欢
    • 1970-01-01
    • 2015-03-26
    • 2014-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-20
    • 2015-11-07
    相关资源
    最近更新 更多