play a sound selected from sp1

fifiddu70

Well-Known Member
Licensed User
Longtime User
I made an Italian Sicilian translator to translator, there are many wave files with phrases in Sicilian, for each selected match the phrase translation and audio files, I hope that when I press the button and tell me by saying the phrase in Italian, the translator I find the sentence and it makes me listen to the translation in Sicilian. the code I posted was an example of my program, I wanted to make sure that we shorten the code.

B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("traduttore")
   p.SetScreenOrientation(1)
   VR.Initialize ("VR")
   tts1.Initialize("tts1")

sp1.Add("abbeverare")
   sp1.Add("accendere")
   sp1.Add("addormentato")
   sp1.Add("annegare")
   sp1.Add("albero")
ens sub

Sub sp1_ItemClick (Position As Int, Value As Object)
   
   If sp1.SelectedItem = "abbeverare" Then
   lbl1.Text = "abbivirari"
   MP.Initialize 
   MP.Load(File.DirAssets,"abbeverare.wav")
   MP.Play
   End If
   
   If sp1.SelectedItem = "accendere" Then
   lbl1.Text = "addumari"
   MP.Initialize 
   MP.Load(File.DirAssets,"accendere.wav")
   MP.Play
   End If
   
   If sp1.SelectedItem = "addormentato" Then
   lbl1.Text = "addummisciutu"
   MP.Initialize 
   MP.Load(File.DirAssets,"addormentato.wav")
   MP.Play
   End If
   
   If sp1.SelectedItem = "albero" Then
   lbl1.Text = "arvulu"
   MP.Initialize 
   MP.Load(File.DirAssets,"albero.wav")
   MP.Play
   End If
end sub

Sub btnDimmi_Click
   VR.Listen
End Sub

Sub VR_Result (Success As Boolean, Texts As List)
    If Success = True Then
     lbl2.Text  = Texts.Get(0)
   End If
   If lbl2.Text = "abbeverare" Then
   lbl1.Text = "abbivirari"
   MP.Initialize 
   MP.Load(File.DirAssets,"abbeverare.wav")
   MP.Play
   
        If lbl2.Text = "accendere" Then
   lbl1.Text = "addumari"
   MP.Initialize 
   MP.Load(File.DirAssets,"accendere.wav")
   MP.Play
        If lbl2.Text = "addormentato" Then
   lbl1.Text = "addummisciutu"
   MP.Initialize 
   MP.Load(File.DirAssets,"addormentato.wav")
   MP.Play
        If lbl2.Text = "albero" Then
   lbl1.Text = "arvulu"
   MP.Initialize 
   MP.Load(File.DirAssets,"albero.wav")
   MP.Play
        If lbl2.Text = "addormentato" Then
   lbl1.Text = "addummisciutu"
   MP.Initialize 
   MP.Load(File.DirAssets,"addormentato.wav")
   MP.Play
   Else 
   Msgbox ("SPIACENTE, FRASE NON TROVATA SUL DATABASE","FRASE    NON PRESENTE")
   End If

End Sub

I am interested in this code

B4X:
Sub VR_Result (Success As Boolean, Texts As List)
    If Success = True Then
     lbl2.Text  = Texts.Get(0)
   End If
   If lbl2.Text = "addormentato" Then
   lbl1.Text = "addummisciutu"
   MP.Initialize 
   MP.Load(File.DirAssets,"addormentato.wav")
   MP.Play
   
   Else 
   Msgbox ("SPIACENTE, FRASE NON TROVATA SUL DATABASE","FRASE NON PRESENTE")
   End If
End Sub

I would like to do in order to play the audio file of selected item on sp1
 

AllyAndroid

Member
Licensed User
Longtime User
how to play a sound for 2 seconds, stop it, and play another sound?

This code will end a sound after 2 seconds. You can modify it to start the next sound using a loop.

B4X:
Sub Process_Globals
   Dim MP As MediaPlayer
End Sub

B4X:
Sub Globals
   Dim timer1 As Timer
End Sub

B4X:
Sub Activity_Resume
   timer1.Initialize("Timer1", 2000)
   timer1.Enabled = True   

   MP.Initialize( )
   MP.Load(File.DirAssets, "sound.wav")
   MP.SetVolume(1, 1)
   MP.Play
End Sub

B4X:
Sub Timer1_Tick
   MP.Stop
   timer1.Enabled = False
End Sub
 
Upvote 0
Top