在项目中的何处存储声音文件以及选择什么解决方案来存储对它们的引用?

发布于 2025-01-03 18:47:11 字数 394 浏览 1 评论 0原文

我正在制作一些奇特的应用程序,需要大量短声音才能使用。有几个问题你也许能回答。

  • 我在android项目中存储的位置有一些限制吗?目前我将它们放在 bin/res/sounds 文件夹中。

  • 文件格式有限制吗?.wav 可以吗?

  • 我需要一些东西来存储对这些声音的引用。我想出了一个字典,其中包含声音名称(键)和文件路径,以便我可以在这样的方法中使用:

    mp = MediaPlayer.create(Test.this, R.raw.mysound);

我应该如何存储 R.raw.mysound,它不是字符串,对吗?

如果我对所有事情都不太清楚,我深表歉意,我会尽力而为。 干杯

I'm making some fancy app which requires lot of short sounds for its use. Got few questions You might be able to answer.

  • Is there some restriction to the place I store then in the android project? Currently I put those in bin/res/sounds folder.

  • Is there a restriction to the format of files and is the .wav ok?

  • I'm gonna need something to store references to those sounds. I came up with a Dictionary which would consist of a sound name (key) and a path to the file so I could use in such method:

    mp = MediaPlayer.create(Test.this, R.raw.mysound);

How should I store R.raw.mysound, it's not a string right?

I apologize If i'm not quite clear about everything, I'm trying my best.
Cheers

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

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

发布评论

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

评论(2

酒浓于脸红 2025-01-10 18:47:11

通常,您会将声音存储在 res 文件夹下的 raw 文件夹中 (res/raw/mySound.wav)。这告诉操作系统不要弄乱它,只需为您复制它即​​可。然后您可以使用您发布的代码行来加载它们。

至于 .wav 格式,可以正常工作,但它会很大。

看看Android支持哪些音频格式:
http://developer.android.com/guide/appendix/media-formats.html

int 中的引用(即 R.raw.mySound)。因此,如果您愿意,您可以将某个字符串映射到该 int,但这真的比使用 R.raw.mySound id 更容易吗?

Usually, you'll store sounds in the raw folder under your res folder (res/raw/mySound.wav). This tells the OS not to mess with it and just copy it over for you. Then you can use the line of code that you posted to load them in.

As for the .wav format that will work fine but it will be really large.

Have a look at what audio formats Android supports:
http://developer.android.com/guide/appendix/media-formats.html

The reference (i.e. the R.raw.mySound) in an int. So you can just map some string to that int if you want but is that really easier than using the R.raw.mySound id?

违心° 2025-01-10 18:47:11

它们不属于 /bin,因为那是自动生成的构建目录。它们确实属于 /res/something,这可能就是您的意思。

R.raw.mysound 是一个 int,所有 R.* 引用也是如此。

.wav 文件虽然很大,但很好。除此之外,您还必须检查目标平台支持什么,以及是否所有设备也都支持它。例如,在Android的早期,平台指定了几种类型,但有些是可选的,由设备决定是否支持。有关完整列表,请参阅:http://developer.android.com/guide/appendix /media-formats.html

They don't belong in /bin, because that is an automatically produced build directory. They do belong in /res/something, which may be what you mean.

R.raw.mysound is an int, as are all R.* references.

.wav files are fine, although big. Anything else and you will have to check both what was supported on your target platform, and whether all devices are likely to support it too. For instance, in the early days of Android, the platform specified several types but some were optional and up to the device as to whether they supported it. For a full list see: http://developer.android.com/guide/appendix/media-formats.html

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