I believe Android uses soundpool.
The advantages of Android soundpool are not mentioned.
What I want to talk about now is
During initialization:
@Override protected void onStart() { mPoolTurnSignal = new SoundPool(1, AudioManager.STREAM_SYSTEM, 100); turnSignal = mPoolTurnSignal.load(this, R.raw.turn_signal, 0);} protected void onResume() { mPoolTurnSignal = new SoundPool(1, AudioManager.STREAM_SYSTEM, 100); turnSignal = mPoolTurnSignal.load(this, R.raw.turn_signal, 0);}private void SetForSingalSound() { if(mSingView.getProtocolLampSignal() != 0 ) { if(PoolState == POOL_PRESTART) { mPoolTurnSignal.play(turnSignal, 1, 1, 0, -1, (float) 0.7); PoolState = POOL_PLAYING; } } else { if(PoolState == POOL_PLAYING) { mPoolTurnSignal.pause(turnSignal); PoolState = POOL_PRESTART; } } }
After play
Pause and stop
Once it is enabled, it cannot be closed.
Depressed for a whole day
Now the problem is found.
private void SetForSingalSound() { if(mSingView.getProtocolLampSignal() != 0 ) { if(PoolState == POOL_PRESTART) {int tt = mPoolTurnSignal.play(turnSignal, 1, 1, 0, -1, (float) 0.7);Log.i("MicroCar:", "SetForSingalSound tt "+tt); PoolState = POOL_PLAYING; } } else { if(PoolState == POOL_PLAYING) { mPoolTurnSignal.pause(turnSignal); PoolState = POOL_PRESTART; } } }
Note that after the red font is changed
You can see logcat.
It turns out that the returned value for each play is changed.
Through logcat, we can see that each time TT is opened, different values are 1, 2, 3, 4, 5, and 6 ....
However, what I disabled or paused before is
Mpoolturnsignal. Pause (turnsignal );
Turnsignal is the first value of initialization, and the value after the second open is different, so it is necessary to pass the response value to close
For example
turnSignal = mPoolTurnSignal.play(turnSignal, 1, 1, 0, -1, (float) 0.7);Log.i("MicroCar:", "SetForSingalSound turnSignal:"+turnSignal);mPoolTurnSignal.pause(turnSignal);
It should be okay now.