Android soundPool 支持扩展吗?
我在onCreate()
方法中编写了这段代码,但没有播放任何内容!
SoundPool mSound = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
AudioManager mAudioManager = (AudioManager)this.getSystemService(Context.AUDIO_SERVICE);
int soundID = mSound.load(this, R.raw.sound1, 1);
int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
mSound.play(soundID, streamVolume, streamVolume, 1, 0, 1f);
问题#1:我的代码有问题吗?我做错了吗?
如果否,
问题 #2:我的声音是 .amr
文件。 SoundPool
支持吗?支持哪些类型?
I wrote this code in the onCreate()
method, but nothing was played !
SoundPool mSound = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
AudioManager mAudioManager = (AudioManager)this.getSystemService(Context.AUDIO_SERVICE);
int soundID = mSound.load(this, R.raw.sound1, 1);
int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
mSound.play(soundID, streamVolume, streamVolume, 1, 0, 1f);
Question #1 : Is there a problem with my code ? Did I do it wrongly ?
If No,
Question #2 : My sound is .amr
file. Is it supported by SoundPool
? What are the supported types ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一切都很好,但您应该在加载后和播放前等待一段时间。加载需要一些时间。您可以借助“OnLoadCompleteListener”检查声音是否已加载。
Everything is fine, but you should wait some time after loading and before play. It takes some time to load. You can check if the sound is loaded with the help of "OnLoadCompleteListener".
代码片段看起来不错。有关支持的格式列表,请参阅文档。看来您必须尝试使用 .mp3 或 .ogg 或 .wav 来代替。根据文档支持 AMR 编解码器,但文件必须采用 .3gp 格式。
The code snippet looks fine. For the list of supported formats refer to the documentation. It looks like you have to try .mp3 or .ogg or .wav instead. AMR codecs are supported according to the docs, but the files have to be in .3gp format.