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,
Non preemptive static priority scheduling algorithm for operating system (C language )Go Language learning notes (GUI programming )XCTF Attack and defense world web Advanced practice _ 2_lottery What's the difference between computer major and training background ?python realization vlookup_ Dry goods I : Why python It's inside vlookup Bubble sort primary springboot2 Separation of front and rear platforms ,token Put in header Pit for verification Python Case conversion of letters ( Two methods )javascript event ( Detailed explanation of zero basis )Unity2019 UIElement note ( ten ) Simple exercise 2