Android声音池功能

标签 android

是否可以检查“声音池”的状态。我想在它开始和停止时执行一些功能。像 ;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/

相关文章:

android - Gradle flavors 和 main 中重复类的解决方法

android - Ubuntu 12.04 编译安卓大师

java - `locationManager.isProviderEnabled(locationManager.GPS_PROVIDER);` 始终返回 true

android - webview调整大小时如何使网页适合webview的宽度(无需重新加载)

android - 当 TextView 中有多于一行输出时,Text 会触及 Parent 的开头

Android:使用处理程序 post.delayed 两次

android - NewStringUTF()/DeleteLocalRef() 产生 JNI 错误(应用程序错误): accessed stale Local

android - RangeTickLabel AndroidPlot 的自定义值

Android 图像按钮 : image with tranparent background

android - 使用游标填充后将项目添加到 ListView