I am trying to intercept the phone volume setting (for music), set it to the max to play a warning through mediaplayer, then reset the phone volume to it's previous level. But It's not working as I think it should.
In Sub Process_Globals I have
Code for setting the volume and playing the warning is:
DDVol is a value set by the user between 0 and 100.
When I run sub PlayWarningSound, the volume is still dependent on the phone's music channel volume (set manually before the sub) - i.e. if the music channel is set to lowest, I don't hear anything, but if the phone volume is at say 50%, I only hear the warning at 50% - even if DDVol is 100.
It seems that "Ph.SetVolume(Ph.VOLUME_MUSIC,MaxVol,False)" does not have any effect here. I've added the "DoEvents", but still no luck.
Am I doing something wrong?
In Sub Process_Globals I have
B4X:
Dim MP1 As MediaPlayer
Dim Ph As Phone
B4X:
Sub PlayWarningSound
Dim PhVol,MaxVol As Float
PhVol = Ph.GetVolume(Ph.VOLUME_MUSIC) 'get current music channel volume
MaxVol = Ph.GetMaxVolume(Ph.VOLUME_MUSIC) 'get max music channel volume
Ph.SetVolume(Ph.VOLUME_MUSIC,MaxVol,False) 'set phone music channel to max volume
DoEvents
MP1.SetVolume(DDVol/100,DDVol/100)
MP1.Play
Ph.SetVolume(Ph.VOLUME_MUSIC,PhVol,False) 'set phone music channel volume back to original
DoEvents
End Sub
When I run sub PlayWarningSound, the volume is still dependent on the phone's music channel volume (set manually before the sub) - i.e. if the music channel is set to lowest, I don't hear anything, but if the phone volume is at say 50%, I only hear the warning at 50% - even if DDVol is 100.
It seems that "Ph.SetVolume(Ph.VOLUME_MUSIC,MaxVol,False)" does not have any effect here. I've added the "DoEvents", but still no luck.
Am I doing something wrong?