来自文件的 SoundPool.load() 和 FileDescriptor

发布于 2024-09-03 22:09:32 字数 625 浏览 8 评论 0原文

我尝试使用带有 FileDescriptor 的 SoundPool 的加载函数,因为我希望能够设置偏移量和长度。文件不存储在资源中,而是存储卡上的文件。即使 SoundPool 的 load 和 play 函数都没有抛出任何异常或将任何内容打印到控制台,声音也不会播放。使用相同的代码,但在 SoundPool 构造函数中使用文件路径字符串效果很好。

这就是我尝试加载的方式(开始等于 0,长度是以毫秒为单位的文件长度):

FileInputStream fileIS = new FileInputStream(new File(mFile));
mStreamID = mSoundPool.load(fileIS.getFD(), start, length, 0);
mPlayingStreamID = mSoundPool.play(mStreamID, 1f, 1f, 1, 0, 1f);

如果我使用它,它会起作用:

mStreamID = mSoundPool.load(mFile, 0);
mPlayingStreamID = mSoundPool.play(mStreamID, 1f, 1f, 1, 0, 1f);

有人有什么想法吗?

谢谢

I tried using the load function of the SoundPool that takes a FileDescriptor, because I wanted to be able to set the offset and length. The File is not stored in the Ressources but a file on the storage card. Even though neither the load nor the play function of the SoundPool throw any Exception or print anything to the console, the sound is not played. Using the same code, but use the file path string in the SoundPool constructor works perfectly.

This is how I have tried the loading (start equals 0 and length is the length of the file in miliseconds):

FileInputStream fileIS = new FileInputStream(new File(mFile));
mStreamID = mSoundPool.load(fileIS.getFD(), start, length, 0);
mPlayingStreamID = mSoundPool.play(mStreamID, 1f, 1f, 1, 0, 1f);

If I would use this, it works:

mStreamID = mSoundPool.load(mFile, 0);
mPlayingStreamID = mSoundPool.play(mStreamID, 1f, 1f, 1, 0, 1f);

Any ideas anyone?

Thanks

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

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

发布评论

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

评论(1

飞烟轻若梦 2024-09-10 22:09:32

也许您已经弄清楚了这一点,但阅读文档后似乎长度可能以字节为单位,而不是毫秒。它指出,如果您在单个二进制文件中存储多个声音,则传递文件描述符非常有用。这意味着您正在告诉系统要提取多个声音中的哪个声音,但我认为它必须能够将其作为单个声音进行处理。因此,如果您将多个波形文件连接在一起,并想要告诉它从二进制文件中播放单个波形文件,则可以使用此方法。

Perhaps you already figured this out, but reading the documentation it seems that length is probably in bytes, not milliseconds. It states that passing a file descriptor is useful if you store multiple sounds in a single binary file. This implies that you are telling the system which sound of the multiples to pull out, but I think it has to be able to process it as a single sound. So this is used if you concatenate several wave files together, and want to tell it to play a single wave file from the binary.

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