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

时间:2011-11-09 17:57:06

标签: 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);

1 个答案:

答案 0 :(得分:0)

您可以访问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.WRITE_EXTERNAL_STORAGE”