(Android版)如何判断一个声音在玩的Soundpool
问题描述:
有没有一种方法,如果某个声音在播放的Soundpool我可以告诉大家?
即。
Is there a way I can tell if a certain sound is playing in SoundPool??? I.E.
if(MySound./*Command Goes Here*/()==true{
//Do stuff
}
我AP preciate如果你能指出我在正确的方向,或给我的code。我无法找到,这是否对文档的任何事情。
在先进的感谢。
I would appreciate if you could point me in the right direction or give me the code. I am not able to find any thing that does this on the docs. Thanks in advanced.
答
这是不可能使用的Soundpool
。
请参阅Android的Soundpool:得到通知时起到结束的另外两个思路:
See Android SoundPool: get notified when end of played for two other ideas:
- 使用
的MediaPlayer
,它提供了一个OnCompletionListener
,而不是的Soundpool
- 使用
的MediaPlayer
与的Soundpool
一起。加载在的MediaPlayer
事先声音得到持续时间和跟踪的声音是否是做打根据其持续时间与的Soundpool $播放时C $ C>。
- Use
MediaPlayer
, which provides anOnCompletionListener
, instead ofSoundPool
- Use
MediaPlayer
in conjunction withSoundPool
. Load the sound in aMediaPlayer
beforehand to get the duration and keep track of whether the sound is done playing based its duration when played withSoundPool
.