是否可以检查“声音池”的状态。我想在它开始和停止时执行一些功能。像 ;mediaplayer 的函数“isplaying()”。声音池有这种功能吗……
最佳答案
不幸的是,SoundPool API 似乎没有提供该功能;它可以让您开始和停止声音,但没有检查其状态的方法。在我的一个应用程序中,我基本上通过维护我自己的 bool 值来绕过它,当我开始声音时我将其设置为真,然后在我停止它或经过足够的时间时设置为假。
//your code to start sound here
long soundStartTime = System.currentTimeMillis();
soundPlaying=true;
//other code here
if(System.currentTimeMillis()-soundStartTime > SOUND_LENGTH_MILLIS){
soundPlaying=false;
//also set false at beginning of level and whenever you stop it manually
关于Android声音池功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4171252/