如何在Android中包含外部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)您确定用户没有删除目录。

记得输入用户权限"android.permission. permission. "WRITE_EXTERNAL_STORAGE"

最新更新