Android Question How to unmute mediaplayer

touchsquid

Active Member
Licensed User
Longtime User
I have an app that plays sounds for starting a yacht race. It worked fine until today, when in testing the app ran fine but made no sounds. It turned out media audio was muted. These sounds are important because you can't expect a skipper starting a race to be watching the phone screen all the time.

Here is the code for one sound:
Code to play one sound. File is loaded earlier.:
Sub Beep
    mpBeep.SetVolume(1,1)
    mpBeep.play
End Sub

I thought setvolume(1,1) would over ride the user mute but apparently not.

Is ther a way to make sure the sounds will always be heard?

Demo of the app:
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can use Phone.SetMute. Make sure to test it with "do not disturb" enabled. The exact behavior depends on the Android version.
 
Upvote 0

touchsquid

Active Member
Licensed User
Longtime User
Mediaplayer setvolume seems to do nothinhg so I commented it out.

This code works.

Code to set phone volume and unmute:
Sub Start
    Try
        p.setvolume(p.VOLUME_MUSIC,VolRange ,True)
        p.setmute(p.VOLUME_MUSIC, False)
    Catch
        ToastMessageShow("START. Do Not Disturb is on.", True)
    End Try   
    'mpStart.SetVolume(1,1)
    mpStart.play
End Sub

Sub VolRange As Int
    Return p.GetMaxVolume(p.VOLUME_MUSIC)
End Sub
 
Upvote 0
Top