Android Question SoundPool StreamType

KZero

Active Member
Licensed User
Longtime User
Hello,
i need to play custom notification sound

Notification builder only support sounds from the external dir which requires writing to sdcard permission and its not suitable for my app

also i tried to load the sound from resources
nb.CustomSound= "android.resource://b4a.example/R.raw.notf"
but it didn't work too

so i decided to use SoundPool to play the notification sound but unfortunately the streamType is hardcoded to STREAM_MUSIC (users always set media volume low)
is it possible to set it to STREAM_NOTIFICATION

thanks in advance
 

stevel05

Expert
Licensed User
Longtime User
Try this:
B4X:
Dim SPJO As JavaObject
        SPJO.InitializeNewInstance("android.media.SoundPool",Array(4,5,0))
        SP = SPJO

Dim Soundpool as Normal, instead of initializing it run the code above and assign it to your Soundpool variable (SP in this case).

4 is the maxstreams value
5 is the Streamtype
0 is srcQuality which actually does nothing.

See https://developer.android.com/reference/android/media/SoundPool.html#SoundPool(int, int, int) for more info.

If you are targeting an API > 21, you may want to try the Soundpool builder instead.

StreamTypes constants can be found here:https://developer.android.com/reference/android/media/AudioManager.html#STREAM_ALARM
 
Upvote 0
Top