Android Question how to get unique exoplayer for each instance

Sifu

Active Member
Hello,

this script puts an image and a player for each music track available in a chosen album.
Up front I don't know exactly how many tracks there are.
I had a same structure with the expandable clv tested, but for that I knew how much tracks there where so that was easier.
So this one scrolls until the last track.
I'd hoped for an unique players, but clearly I seem not getting the idea how to do it.
Also now each player reacts on the other playing together but only one track and the Next button plays the next song which should not happen. If a player is started then another should stop.
Also from the expandable clv I know that in that case the Next button does not go to the next track.

But for it's just a CLV.

This is the script calling the next script but here you see the repeat loop.

B4X:
Sub FillCLV
    Log("start FillCLV")
    clv1.Clear
    TrkImage.Initialize("")
    
    Dim sources1 As List
    sources1.Initialize
    
    ''''''playerJ.Prepare(playerJ.CreateListSource(sources1))
        
    Dim trackpic As String
    If albumtrackpics.IsInitialized Then                  
    Log("albumtrackpics= " & albumtrackpics.Get(0))
    For i = 0 To albumtrackpics.Size -1
        trackpic = albumtrackpics.Get(i)
        Log("trackpic= " & trackpic)
        '''''playerJ.Initialize("playerJ")
        playerJ.Prepare(playerJ.CreateListSource(sources1))
        Dim p1 As B4XView = CreateItem((0xFF000000), TrkImage, playerJ)
        clv1.Add(p1,"")
    Dim tr As Int
    tr = i + 1              'there is no 0.mp3 so add 1
        DownloadImage(trackpic, TrkImageView)             'correct name is in albumtrackpics.Get(i)
        sources1.Add(playerJ.CreateUriSource("https://trackshere.com/albumtracks/" & albumnamempthree & "/" & tr & ".mp3"))
    Next
    End If
End Sub
I don't think I can do like: player(i).Prepare(playerJ.CreateListSource(sources1)) ?

Does anyone can give a push in the right direct how I should do this?
If it's not possible then another thing I can try is to just have 1 player and use the next button to display the Image and play the next track. In that case there is no scrolling needed. and not all images have to be downloaded in one go (not using lazy loading here).

Thanks for any help!
 

Sifu

Active Member
Found the culprit
What I had to do was: put these lines in the loop and not outside.
B4X:
playerJ.Initialize("playerJ")    <----also it seems I had this one commented out
            Dim sources1 As List  <----these
            sources1.Initialize       <--- these
and put this line:
B4X:
        playerJ.Prepare(playerJ.CreateListSource(sources1))
below this line
B4X:
sources1.Add(playerJ.CreateUriSource("https://........etcetera....

Now it works as wanted, each player a single different track, and the next button does nothing. The previous button just return to the start of the track.
(so I did not need SMM in this case)
Thanks!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…