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

发布于 2024-12-14 12:56:16 字数 287 浏览 3 评论 0原文

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

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

A few WAV files used by my app are currently located in res/raw. These files need to be accessible by the user after the app is installed. So ideally my app should create a folder on the device and put the files in it. Any idea/suggestions on how to do this?

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清醇 2024-12-21 12:56:16

您可以访问 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”放入清单中

You can access the sd_card, so you can create a directory and put there your files

// 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);

The output file should be your sound that you have loaded from res/raw.
My advice would be to just copy the sound to the folder, and still use the sound from res/raw from within your app because

1) it is easier since you can access it as a resources

2) you are sure the user didn't deleted the directory.

Remember to put the user permission "android.permission.WRITE_EXTERNAL_STORAGE" in the manifest

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文