Android Question Simultaneous Playing with MediaPlayer

Ferdari

Active Member
Licensed User
Longtime User
Hello,

I was trying to play 2 or more sound in different interfaces generated Dynamically of MediaPlayer, but im getting:
B4X:
java.lang.ArrayIndexOutOfBoundsException: length=2; index=2




My code:
B4X:
Sub Play_Sound(Snd As String)
    Dim media As String
    Dim mps() as MediaPlayer

    For i = 0 To 2 -1
       Log(i)
       If Not(mps(i).IsPlaying) Then
         mps(i).Initialize()
         media="sounds/" & Snd
         mps(i).Load(File.DirAssets,media)
         mps(i).Play
         Exit
       End If
       Next
End Sub

Im newbie using MediaPlayers, i dont know how to create dynamically MediaPlayers and use it, without handling too much and limited IFs like
B4X:
if mps1.IsPlaying then
   mps2.Load(...)
   mps2.Play
And so on mediaplayer3,4,5,6...

Can anyone help me?
 
Last edited:

Ferdari

Active Member
Licensed User
Longtime User
how do i need to fill the array in order to work?

i tried almost everything



Thanks
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…