I'm trying to play an audio alarm when the phone is locked to alert the user.
I have been using the SoundPool.Play method, but this plays by via the Music / media channel which the user typically has turned down on their device.
I've adjusted the Play volume in the PLAY call, but the volume is a still prodeminatly controlled by the users media volumn setting.
So now I'm looking to play the alert via the ALARM channel as I'm hoping that the volume on that will not be adjusted by the user as often.
I notice on the android documentation that the SoundPool initializer can take a few paramenters. One of them is the channel to play on - such as the ALARM channel.
In B4A it looks like we can only initialize the soundpool on the default Music / Media channel.
Do you know if it is possible to play audio filles via the ALARM channel ? Is there a way to set the soundpool to use the prefered channel ?
The code above worked perfectly.
For anyone else - you just need to declare an instance of the phone object to use the Phone.Volume_alarm .... Dim phone as Phone
The code above worked perfectly.
For anyone else - you just need to declare an instance of the phone object to use the Phone.Volume_alarm .... Dim phone as Phone
@aregan, please, before you go! How did you play it without media player ? Below code is not working for me
Dim phone As Phone
Dim sp As SoundPool
Dim jo As JavaObject
jo.InitializeNewInstance("android.media.soundpool", Array(4, phone.VOLUME_ALARM, 0))
sp = jo
Dim PoolID As Int = sp.Load(File.DirInternal, name)
sp.Play(PoolID,1,1,1,0,1)
Thanks, Jeffrey, now it doesn't crash, but I couldn't here any sound play on .wav files. Is anything still needed in the code? It crashed before but stable now, but no sound play
@aregan, please, before you go! How did you play it without media player ? Below code is not working for me
Dim phone As Phone
Dim sp As SoundPool
Dim jo As JavaObject
jo.InitializeNewInstance("android.media.soundpool", Array(4, phone.VOLUME_ALARM, 0))
sp = jo
Dim PoolID As Int = sp.Load(File.DirInternal, name)
sp.Play(PoolID,1,1,1,0,1)
Dim jo As JavaObject
Dim ph As Phone
Dim AlertSoundPlayID As Int
jo.InitializeNewInstance("android.media.SoundPool", Array(4, ph.VOLUME_ALARM, 0)) '4 = max streams
soundsAlarmChannel = jo
soundid_notification = soundsAlarmChannel.Load(File.DirAssets,"notification.wav")
AlertSoundPlayID = soundsAlarmChannel.Play(soundid_notification,1,1,1,-1,1)
Dim jo As JavaObject
Dim ph As Phone
Dim AlertSoundPlayID As Int
jo.InitializeNewInstance("android.media.SoundPool", Array(4, ph.VOLUME_ALARM, 0)) '4 = max streams
soundsAlarmChannel = jo
soundid_notification = soundsAlarmChannel.Load(File.DirAssets,"notification.wav")
AlertSoundPlayID = soundsAlarmChannel.Play(soundid_notification,1,1,1,-1,1)