android - 如何在Android中包含外部WAV文件

标签 android audio storage external wav

我的应用程序使用的一些WAV文件当前位于res/raw中。安装应用程序后,用户需要可以访问这些文件。因此,理想情况下,我的应用程序应在设备上创建一个文件夹并将文件放入其中。关于如何执行此操作的任何想法/建议?

soundIds[0] = soundPool.load(test2Activity, R.raw.snare, 1);
        soundIds[1] = soundPool.load(test2Activity, R.raw.snare2, 1);

最佳答案

您可以访问sd_card,因此可以创建目录并在其中放置文件

// create a File object for the parent directory
File yourDirectory = new File("/sdcard/YourDirectory/");
// have the object build the directory structure, if needed.
yourDirectory.mkdirs();
// create a File object for the output file
File outputFile = new File(yourDirectory, filename);
// now attach the OutputStream to the file object, instead of a String representation
FileOutputStream fos = new FileOutputStream(outputFile);

输出文件应该是您从res / raw加载的声音。
我的建议是仅将声音复制到文件夹,并仍在应用程序中使用res / raw中的声音,因为

1)更容易,因为您可以将其作为资源进行访问

2)您确定用户没有删除目录。

切记在 list 中放入用户权限“android.permission.WRITE_EXTERNAL_STORAGE”

关于android - 如何在Android中包含外部WAV文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8069369/

相关文章:

regex - Dart/Flutter 读写列表列表 - 为什么我无法使用索引号访问列表列表中的对象?

android - 无法写入内部存储器android

android - 在 Android 上使用 Google API Java 客户端,POST 请求似乎没有使用 OAuth 通过 Google App Engine 应用程序进行身份验证

java - 如何在textView中显示多个值

c - 在 portaudio 中管理 channel

matlab - 谐波产品频谱的MATLAB代码

windows - Windows C盘上的实际可用空间是多少

java - 如何在 fragment 中使用 Google MapView?

android - ListView 每行 2 个项目

android - 在Android Studio应用程序上添加声音