Android sound SoundPool: soundpool 1 not retry
SoundPool is used in development today. When soundpool 1 not retry cannot play the sound, MediaPlay can
After some research, we found that:
Unable to play the sound because of the soundpool 1 not retry error code
Mgr = (AudioManager) MainActivity. this. getSystemService (Context. AUDIO_SERVICE );
// Initialize the soundPool object. The first parameter is the number of sound streams that can be played simultaneously. The second parameter is the sound type, and the third parameter is the sound quality.
SoundPool = new SoundPool (4, AudioManager. STREAM_MUSIC, 100 );
SoundPoolMap = new HashMap <Integer, Integer> ();
SoundPoolMap. put (1, soundPool. load (MainActivity. this, R. raw. or, 1 ));
SoundPoolMap. put (2, soundPool. load (MainActivity. this, R. raw. sd, 1 ));
Volume = mgr. getStreamVolume (AudioManager. STREAM_MUSIC );
// Loop: the loop mode in the loop (0 = No loop,-1 = infinite loop)
SoundPool. play (soundPoolMap. get (1), volume, volume, 1, 0, 1f );
Solution: the problem here is soundPool. load (MainActivity. this, R. raw. or, 1), that is, after loading () the audio file, play () immediately. The system has not prepared the sound file, so the problem has occurred.
Here you need to: load () in other places first, for example, load () in the constructor, and then call play () Where you need to play (), that is, it takes a while to call play ()
This is the case.
Mgr = (AudioManager) MainActivity. this. getSystemService (Context. AUDIO_SERVICE );
// Initialize the soundPool object. The first parameter is the number of sound streams that can be played simultaneously. The second parameter is the sound type, and the third parameter is the sound quality.
SoundPool = new SoundPool (4, AudioManager. STREAM_MUSIC, 100 );
SoundPoolMap = new HashMap <Integer, Integer> ();
SoundPoolMap. put (1, soundPool. load (MainActivity. this, R. raw. or, 1 ));
SoundPoolMap. put (2, soundPool. load (MainActivity. this, R. raw. sd, 1 ));
Volume = mgr. getStreamVolume (AudioManager. STREAM_MUSIC );
Try {
Thread. sleep (1000 );
} Catch (InterruptedException e ){
// TODO Auto-generated catch block
E. printStackTrace ();
}
SoundPool. play (soundPoolMap. get (1), volume, volume, 1, 0, 1f );