Android Question Click sound on buttons unreliable

Roger Daley

Well-Known Member
Licensed User
Hi All

I have an App with a number of buttons which have the option of making a "click" sound when pressed. I have used Media Player and a sound file [7ms] to do this, however the "click" sound does not always work. It's operation is intermittent and unpredictable.
Possibly there is a better way to use Media Player or even a better way to make a button "click".

Any sugestions welcome.

Regards Roger

B4X:
Sub Process_Globals
    Dim MP As MediaPlayer
        Dim  btnClick_flag  As Int

        Etc........
End Sub

Sub Activity_Create(FirstTime As Boolean)
    If FirstTime Then
        MP.Initialize2("MP")
        MP.Load(File.DirAssets,"click.wav")
               Etc............
       End If
End Sub

Sub AnyButton_Click
    If btnClick_flag = 1 Then MP.Play
        Etc..........
End Sub
 

Peter Simpson

Expert
Licensed User
Hello @Roger Daley,
Try this code out.
B4X:
You will need to check the 'Audio' library in your library tab

    Dim Beep As Beeper 'Place in Sub Globals 
        Beep.Initialize(100, 1000) 'Place in Activity_Create. Adjust the duration and frequency until you get the desired click sound 

        Beep.Beep 'Call in button sub whenever you want hear hear beep/click sound
Enjoy...
 
Top