Application and phone freeze

omoba

Active Member
Licensed User
Longtime User
Hi,

I just wrote a program that plays audio files from a selected range. Once the play button is clicked, the audio at the beginning of the range start playing, when that audio is done playing, the next audio up is played, this continues until the whole audio in the range are played.

My problem is that once the audio files starts playing, I loose control of the whole app and phone.

As per the app control I cant do anything in the app, as per the phone (increase or decrease audio, exit app, go to home etc) all of these dont work too. I noticed that the pushing of phone control would finally crash the app.

Pls any ideas. I think the problem is a "Do While" loop in effect while audio files are playing. I am looping because I want each playing audio to finish before moving to the next. I have noticed this issue before in VB.

Below is the code


Sub Spinner3_ItemClick (Position As Int, Value As Object)
store1 = Spinner3.SelectedItem
End Sub

Sub Spinner4_ItemClick (Position As Int, Value As Object)
store2 = Spinner4.SelectedItem
End Sub

Sub Button1_Click
i = 0
MP.Load(File.DirAssets, Spinner1.SelectedItem & "/" & store1 & ".mp3")
MP.play
Playing
End Sub

Sub Playing
Do While MP.IsPlaying
i = i + 1
Loop

If store2 = store1 Then
store1 = Spinner3.SelectedItem
store2 = Spinner4.SelectedItem
Return
End If

store1 = store1 + 1
Button1_Click

End Sub


Sub Button2_Click
MP.Stop
End Sub


:sign0085:
 

omoba

Active Member
Licensed User
Longtime User
Thanks

The reason i am looping is i want the current audio file playing to end before going to the next audio file.

In the code I select a queue of audio files to play by setting a number range using Spinner3.SelectedItem and Spinner4.SelectedItem.

So the app starts playing Spinner3.SelectedItem and then increase the number to play the next audio file. The playing would end when the values of Spinner3.SelectedItem and Spinner4.SelectedItem are equal.

I added the loop make sure the current playing file end before the next file is played.

I have thought of timer --still trying to get it to work.
 
Upvote 0

mc73

Well-Known Member
Licensed User
Longtime User
Create a timer, placing inside, a check for
B4X:
mp.isPlaying=false
in order to proceed to the very next song in your list if isPlaying signals the end of the song. Pausing can be captured in your activity_pause sub.
 
Upvote 0

margret

Well-Known Member
Licensed User
Longtime User
You could do something like this in the Timer1 Tick Event:

B4X:
Sub Timer1_Tick
    'Call sub once a second
    If MP.IsPlaying = False AND LC < MaxCount Then
        MaxCount = MaxCount +1 'Play next sound
        'Play next song or call sub to start next song
    Else
        'Max songs selected has been played
        Timer1.Enabled = False
    End If
End Sub
 
Upvote 0
Top