Android Question soundpool(looping) problem

MasterGy

Member
Licensed User
Hi !
if you want to test whether all sounds are heard, I'm curious.
The soundpool 'loop' doesn't always work. The program has several loops, the playback speed and volume of which must be constantly modified in real time. I did a trick that starts the sound samples continuously in the first two seconds when the program is started, not looped. I noticed that it doesn't load when loaded. but if I force it to play in series, it loads. After the first two seconds, it only starts them once, looped, and I can control that. But this only works when the phone is not loaded. I'm curious how the sounds work on you. Then the good thing is that you hear what you hear in the video.
Do you know a reliable way to use soundpool, or an alternative solution that allows you to change the playback speed?

(top slider is the height of the terrain, control by touching. Hold it and you'll get it)


 

kimstudio

Active Member
Licensed User
Longtime User
Just had a chance to confirm:

屏幕截图 2024-12-04 184408.png



@Erel : Rate should be from 0.5 to 2 for speed change instead of (0 - 2) in the doc.

public final int play (int soundID, float leftVolume, float rightVolume, int priority, int loop, float rate)​

Added in API level 1
Play a sound from a sound ID. Play the sound specified by the soundID. This is the value returned by the load() function. Returns a non-zero streamID if successful, zero if it fails. The streamID can be used to further control playback. Note that calling play() may cause another sound to stop playing if the maximum number of active streams is exceeded. A loop value of -1 means loop forever, a value of 0 means don't loop, other values indicate the number of repeats, e.g. a value of 1 plays the audio twice. The playback rate allows the application to vary the playback rate (pitch) of the sound. A value of 1.0 means play back at the original frequency. A value of 2.0 means play back twice as fast, and a value of 0.5 means playback at half speed.

Parameters​

soundIDa soundID returned by the load() function
leftVolumeleft volume value (range = 0.0 to 1.0)
rightVolumeright volume value (range = 0.0 to 1.0)
prioritystream priority (0 = lowest priority)
looploop mode (0 = no loop, -1 = loop forever)
rateplayback rate (1.0 = normal playback, range 0.5 to 2.0)
 
Upvote 0

MasterGy

Member
Licensed User
Just had a chance to confirm:

View attachment 159211


@Erel : Rate should be from 0.5 to 2 for speed change instead of (0 - 2) in the doc.

public final int play (int soundID, float leftVolume, float rightVolume, int priority, int loop, float rate)​

Added in API level 1
Play a sound from a sound ID. Play the sound specified by the soundID. This is the value returned by the load() function. Returns a non-zero streamID if successful, zero if it fails. The streamID can be used to further control playback. Note that calling play() may cause another sound to stop playing if the maximum number of active streams is exceeded. A loop value of -1 means loop forever, a value of 0 means don't loop, other values indicate the number of repeats, e.g. a value of 1 plays the audio twice. The playback rate allows the application to vary the playback rate (pitch) of the sound. A value of 1.0 means play back at the original frequency. A value of 2.0 means play back twice as fast, and a value of 0.5 means playback at half speed.

Parameters​

soundIDa soundID returned by the load() function
leftVolumeleft volume value (range = 0.0 to 1.0)
rightVolumeright volume value (range = 0.0 to 1.0)
prioritystream priority (0 = lowest priority)
looploop mode (0 = no loop, -1 = loop forever)
rateplayback rate (1.0 = normal playback, range 0.5 to 2.0)
thanks! sorry for not replying! I understand the use of soundpool, you can also hear me setting the playback speed in the video. My problem with it is its unreliability. After loading, it is uncertain that it starts playing on the first few calls. This is not a problem with sounds that always have to be played again, and then you don't have to deal with it, because the next one comes anyway. The problem is with 'loop' sounds. Because you have to start them once, and then set them (volume, rate). But if they don't start at the beginning of the program, then they won't start after that either. And unfortunately I can't read anywhere whether the actual playback has been implemented. I noticed that if the phone is loaded, it won't load at that moment, and you have to wait a bit before starting the loop. I don't think this is a good solution because I still can't know whether it managed to start it or not. There is no problem with Samsung phones, but on Xiaomi, soundpool works unreliable.
 
Upvote 0

kimstudio

Active Member
Licensed User
Longtime User
I have no access to google drive so have not tried your app. Could you send me by email kimstudio@163.com if convenient? I'd like to try.

I guess for stable sound application self managed playback using audiotrack or other game engines with audio can be exploited.
 
Upvote 0
Top