In the development, we meet the need to play small audio , I thought of it for the first time soundpool But there were two holes , Now let's share the solution
1.soundpool After loading , But there was no sound
@Override public void speak(Object content) { SoundPool mSoundPool = new
SoundPool(5, AudioManager.STREAM_ALARM, 5); int soundID = mSoundPool.load(
mContext,(Integer) content, Integer.MAX_VALUE);, 0.6f,
0.6f, 1, 0, 1); } Last check api Found the problem , SoundPool Provides a callback to monitor the completion of loading resources public void
setOnLoadCompleteListener(OnLoadCompleteListener listener) Just play the sound in this callback :
@Override public void speak(Object content) { SoundPool mSoundPool= new
SoundPool(5, AudioManager.STREAM_ALARM, 5); final int soundID = mSoundPool.load(
mContext,(Integer) content, Integer.MAX_VALUE);
mSoundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
@Override public void onLoadComplete(SoundPool soundPool, int sampleId, int
status) {, 0.6f, 0.6f, 1, 0, 1); } }); }
2. many times stop/pause be unable to stop
The problem is that every time you play it, 0.6f, 0.6f, 1, 0, 1); The one in the callback later soundID It will change :
` public final int play(int soundID, float leftVolume, float rightVolume,int
priority, int loop, float rate)` Try redefining a variable playId
To store the return value , Make sure it's for the same one every time soundpool The problem is solved by pausing and playing playId=,
0.1f, 0.1f, 1, -1, 1); Pass this when you need to pause playId

©2019-2020 Toolsou All rights reserved,
Digital rolling lottery program Keras Save and load model (JSON+HDF5) Remember once EventBus Project issues caused by memory leaks I've been drinking soft water for three years ? What is the use of soft water and water softener msf Generate Trojan horse attack android mobile phone Time conversion front desk will 2020-07-17T03:07:02.000+0000 Into 2020-07-17 11:07:02 Chuan Shen 1190 Reverses the substring between each pair of parentheses leetcodehive Summary of processing methods for a large number of small files SparkSQL Achieve partition overlay write Image format conversion