How to play multi wave files one by one?

susu

Well-Known Member
Licensed User
Longtime User
I need to play multi wave files one by one. I tried SoundPool but it play all files at the same time. I tried mediaplayer with this code:

B4X:
Sub PlaySound (Dir,FileName)
Do While mp.IsPlaying
DoEvents
Loop
mp.Load(Dir, FileName)
mp.Play
End Sub

But on device with slow CPU it seems "block" everything until finish playing. Is there any better way to do it?
Thank you for your help.
 

LittleEddie

Member
Licensed User
Longtime User
One way is to use a timer and check it

I normally use .Position and .Duration.

And you should avoid using DoEvents and use a timer.

Ed
 
Last edited:
Upvote 0

stevel05

Expert
Licensed User
Longtime User
If you are aiming to play the music in the background while the app is doing something else the Do loop with DoEvents is unnecessary and will as you say, take a lot of cpu and stop much else happening.

You would be better looking for another sub that is called regularly, a screen refresh maybe, and check if the if the player has finished in there, then load the next file if it has.

Steve
 
Upvote 0

susu

Well-Known Member
Licensed User
Longtime User
One way is to use a timer and check it

I normally use .Position and .Duration.

And you should avoid using DoEvents and use a timer.

Ed

I also think about it. Can you share your code? Thank you.
 
Upvote 0
Top