我的应用程序使用的一些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/