Android Question 2 sounds panel in same time

Douglas Farias

Expert
Licensed User
Longtime User
hi how can i make to allow the user to touch 2 panel in same time and it give a sound?
this is my code i m trying to make a drum app.
I m using gestures and it is ok but when you need press 2 panel in same time itdont give sound

i go send the apk demo for all understand.

can someone help me on this? i m trying but i dont understand what to make now =(


B4X:
#Region  Project Attributes
    #ApplicationLabel: Bateria
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: landscape
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: True
    #IncludeTitle: False
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim bumbos,tarols,chipos As Int
    Dim sp As SoundPool
    Dim g As Gestures
    Dim Panel2, panel3, panel4 As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")
    Panel2.Initialize("Panel2")
    'Panel2.Color = Colors.LightGray
    Panel2.Tag = "Panel2"
   
    panel3.Initialize("Panel3")
    'panel3.Color = Colors.LightGray
    panel3.Tag = "Panel3"
   
    panel4.Initialize("Panel4")
    'panel4.Color = Colors.LightGray
    panel4.Tag = "Panel4"
   
    'Panel3.Initialize("Panel3")
    g.SetOnTouchListener(Panel2, "Panel2_GesturesTouch")
    g.SetOnTouchListener(panel3, "Panel3_GesturesTouch")
    g.SetOnTouchListener(panel4, "Panel4_GesturesTouch")
   
Activity.AddView(Panel2, 38%x, 50%y, 35%x, 50%Y) 'bumbo

Activity.AddView(panel3, 21%x, 50%y, 17%x, 45%Y) 'tarol

Activity.AddView(panel4, 1%x, 55%y, 20%x, 23%Y) 'chipo

   
    sp.Initialize(100)
    bumbos = sp.Load(File.DirAssets, "bumbo.mp3")
    tarols = sp.Load(File.DirAssets, "tarol.mp3" )
    chipos = sp.Load(File.DirAssets, "chipo.mp3" )
   

End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub Panel2_GesturesTouch(o As Object, ptrID As Int, action As Int, x As Float, y As Float) As Boolean

            sp.Play(bumbos ,1,1,1,0,1 )

    Return False ' need to return true otherwise we don't get any other events in the gesture

End Sub

Sub Panel3_GesturesTouch(o As Object, ptrID As Int, action As Int, x As Float, y As Float) As Boolean

            sp.Play(tarols ,1,1,2,0,1 )

    Return False ' need to return true otherwise we don't get any other events in the gesture

End Sub

Sub Panel4_GesturesTouch(o As Object, ptrID As Int, action As Int, x As Float, y As Float) As Boolean

            sp.Play(chipos ,1,1,2,0,1 )

    Return False ' need to return true otherwise we don't get any other events in the gesture

End Sub
 

Attachments

  • result.apk
    369.2 KB · Views: 169

stevel05

Expert
Licensed User
Longtime User
Return True from the GesturesTouch subs
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
yes i tested your exemple give 2 clicks when you press 1 time the panel.
i tryed to make a other panel and dont give sound in same time
for exemple your press panel1 and panel2 same time give only panel1 sound o_O
i dont know why this i tryed to return true too but dont work.

when i press panel1 50x fast for exemple, it give me 50 sounds normal
but when i press panel1 and panel2 dont work *-* and i need to make this to work the drum app need press 2 or 3 panels in same time to play drum
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
yes i tested your exemple give 2 clicks when you press 1 time the panel.
I've just tested it again and it doesn't sound twice for me.

I also ran this, although there are no sounds, you can see that all three panels respond:

B4X:
#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
   
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim Gest As Gestures
    Private Panel1 As Panel
    Private Panel2 As Panel
    Private Panel3 As Panel
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("1")

    Gest.SetOnTouchListener(Panel1,"P1_Gest")
    Gest.SetOnTouchListener(Panel2,"P2_Gest")
    Gest.SetOnTouchListener(Panel3,"P3_Gest")
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub
Sub P1_Gest(V As Object,Ptr As Int,Action As Int,X As Float,Y As Float) As Boolean
    If Action = 0 Then
        Log("P1 Touched")
        Return True
    End If
End Sub
Sub P2_Gest(V As Object,Ptr As Int,Action As Int,X As Float,Y As Float) As Boolean
    If Action = 0 Then
        Log("P2 Touched")
        Return True
    End If
End Sub
Sub P3_Gest(V As Object,Ptr As Int,Action As Int,X As Float,Y As Float) As Boolean
    If Action = 0 Then
        Log("P3 Touched")
        Return True
    End If
End Sub

The best thing you can do is zip and post your project, so we can test it with your sounds.

What device are you testing it on?
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
ok i m not in home when i go to home i send to you very thx for your all helps steve
 
Upvote 0
Top