Android Question Update score

joop

Active Member
Licensed User
Longtime User
My code :

B4X:
Sub Button1_Click

MediaPlayer1.Load(File.DirAssets, "pingpoints.mp3")

For i = 1 To 5
  Label1.Text = i
  MediaPlayer1.play 
  Do While MediaPlayer1.IsPlaying
  Loop
Next 
 
End Sub

I am using a Label to count the score , I thought it would be nice to hear a sound when
one point is made , and so on until 5 points.

This is what i want:
label displays 1
sound
label displays 2
sound

until5

This is what I got :

label displays 00
sound
sound
sound
sound
sound
label displays 05

Maybe I am thinking to simple a file is attached. see the attached file.
 

Attachments

  • score.zip
    11.5 KB · Views: 134

joop

Active Member
Licensed User
Longtime User
B4X:
For i = 1 To 6
   player_points_label.Text = i
  DoEvents                  ' show points increasing
  MediaPlayer1.play 
  Do While MediaPlayer1.IsPlaying
  Loop   
Next

Hi Erel,This works on my Samsung but probably wont work always , what
should I do within the MediaPlayer_Complete event. ? and how can I do
this without some kind of loop ?.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
#Region  Activity Attributes
   #FullScreen: False
   #IncludeTitle: True
#End Region

Sub Process_Globals
   Private mp As MediaPlayer
End Sub

Sub Globals
   Dim label1 As Label
End Sub

Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
     mp.Initialize2("mp")
     mp.Load(File.DirAssets, "sound.mp3")
   End If
   label1.Initialize("")
   Activity.AddView(label1, 10dip, 10dip, 100dip, 50dip)
   Play
End Sub

Sub Play
   label1.Text = 0
   mp_Complete
End Sub

Sub mp_Complete
   If label1.Text < 5 Then
     mp.Play
     label1.Text = NumberFormat(label1.Text + 1, 0, 0)
   End If
End Sub
 
Upvote 0
Top