soundpool 播放无声音 sample 1 not ready


解决办法:
是因为资源还没加载好
起一个handler延迟一些时间加载就好:
public static void startCameraKacha(Context c) {
final SoundPool soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100);
AudioManager mgr = (AudioManager) c.getSystemService(Context.AUDIO_SERVICE);
float streamVolumeCurrent = mgr.getStreamVolume(AudioManager.STREAM_MUSIC);
float streamVolumeMax = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
final float volume = streamVolumeCurrent / streamVolumeMax;
final int id = soundPool.load(c, R.raw.kacha, 1);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
soundPool.play(id, volume, volume, 1, 0, 1f);
}
}, 20);
}


你可能感兴趣的:(soundpool 播放无声音 sample 1 not ready)