I think I've discovered why my code doesn't change the ringer volume. I've been thinking about this problem for days. Erel gave me the code that plays the phone ringer tone via the Media Player. My code below is trying to change the ringer volume but I think it needs to change the
media player volume, not the ringer volume.
What I'm trying to do with playing the ringer tone via the media player is to simulate the phone ringing sound and then I'm trying to dynamically adjust the volume...but since I'm using the media player (per Erel suggestion), I need to adjust the
media player sound level to
simulate adjusting the ringer volume. I'll have to figure out a ratio between the max vol levels of the media player and the ringer max vol.
I've been looking at the Android SDK Media Player docs and see that I will need to use:
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
int curVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, arg1, 0);
But I see in b4a popup help for the media player that there is no setAudioStream, no getStreamMaxVolume, no getStreamVolume and no setStreamVolume methods
So can someone help me convert over these 3 SDK methods into b4a methods that I can then use?
Thank you very much...
Sub Process_Globals
Dim mp As MediaPlayer
Dim p As Phone
End Sub
Sub btn_Set_Volume12_Click
p.SetRingerMode(p.RINGER_NORMAL)
p.SetVolume (p.VOLUME_RING, 8, True)
mPhoneVolume = p.GetVolume(p.VOLUME_RING)
mPhoneMaxVolume = p.GetMaxVolume (p.VOLUME_RING)
mPhoneRingerMode = p.GetRingerMode
lbl_Status.Text = "Ringer Mode:" & mPhoneRingerMode & " Volume:" & mPhoneVolume & " Max Volume:" & mPhoneMaxVolume
End Sub
Sub btn_Set_Volume4_Click
p.SetRingerMode(p.RINGER_NORMAL)
p.SetVolume (p.VOLUME_RING, 4, True)
mPhoneVolume = p.GetVolume(p.VOLUME_RING)
mPhoneMaxVolume = p.GetMaxVolume (p.VOLUME_RING)
mPhoneRingerMode = p.GetRingerMode
lbl_Status.Text = "Ringer Mode:" & mPhoneRingerMode & " Volume:" & mPhoneVolume & " Max Volume:" & mPhoneMaxVolume
End Sub
Sub btn_Play_Ringtone_Click
PlayRinger
End Sub
Sub PlayRinger
Dim r As Reflector
r.Target = "ContentDir"
r.Target = r.RunMethod("intern")
mp.Load(r.Target, "content://settings/system/ringtone")
mp.Play
End Sub