Android Question How to catch Exoplayer buttons to be able to pause a player when another starts


Active Member

how do I catch the clickitems of the Exoplayer when it's placed on the clv?
It seems the player buttons are not catched.
What I want is that other players stop when a player is started, now they just play thru each other.

I also tried the expandable_clv in another project and with that you can use the status of the expanded item to stop another player,
except when 2 or 3 are expanded then multiple players can play at once which I don't want.

For this project the players are put under each other and the nr of players depend on how many music tracks there are in an album.

Sub FillCLV
    Log("start FillCLV")
    Dim sources1 As List
    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)
        Dim p1 As B4XView = CreateItem((0xFF000000), TrkImage, playerJ)
    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("" & albumnamempthree & "/" & tr & ".mp3"))
    End If
End Sub

Sub CreateItem(clr As Int,  trkimg As ImageView, player As B4XView) As B4XView
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, clv1.AsView.Width,260dip) ', clv1.AsView.Height)

    TrkImageView.Bitmap = trkimg.Bitmap
    SimpleExoPlayerView1.Player = player
    SimpleExoPlayerView1.Tag = player
    'SimpleExoPlayerView1.ControllerTimeout = -1
    'SimpleExoPlayerView1.UseController = False
    VideoPlayers.Put(SimpleExoPlayerView1, True)
    Dim jo As JavaObject = SimpleExoPlayerView1 'this stops controlbuttons from fading away on player
    jo.RunMethod("setControllerShowTimeoutMs", Array(0))
    jo.RunMethod("setControllerHideOnTouch", Array(False)) 'this line prevents remove of controls, when touch on outer left or right side
    Return p    
End Sub

Sub clv1_ItemClick (Index As Int, Value As Object)
    Log("Clicked on clv1")
    Log("index: " & Index & "Value: " & Value)
    Dim MyVal As String = Value
    Dim item() As String = Regex.Split(",", MyVal)
    Log("item " & item(0)) 'this show Expanded=false or Expanded=True
    Dim JaNee As String = item(0)
    Dim TF() As String = Regex.Split("=", JaNee)
    Log("TF: " & TF(0))
    Dim components() As String
    components = Regex.Split("=", item(0)) 'returns: "abc", "def", "", "ghi"
    Log ("components: " & components(0))
    Dim tbState As Boolean
    If components(0) = "true" Then
        tbState = True
            tbState = False
    End If
    Private id As Int
    id = Index' + 1
    'If id = 0 And tbState = True Then
    If id = 0 Then
    End If
        Log("itemclickerror: " & LastException.Message)
    End Try
End Sub

Trying to test some things which gave no result yet:
Sub SimpleExoPlayerView1_Click
End Sub

Private Sub Music_Click 
End Sub

Private Sub VideoClips_Click
End Sub

Sub Player_ItemClick (Index As Int, Value As Object)
Log("playerIndex: " & Index)
Log("playerValue: " & Value)
End Sub

Does anyone have a idea how to solve this? I searched but could not find an answer, nor that it was asked before.

Many Thanks for any help!


Active Member
the 2nd line of what I added from example via the link above gives an error
Dim jo As JavaObject = playerJ
    Dim event As Object = jo.CreateEventFromUI("$EventListener", "statechanged", False) '----this line gives an error
    jo.GetFieldJO("player").RunMethod("addListener", Array(event))
the line is exactly as the line here:
java.lang.RuntimeException: java.lang.ClassNotFoundException:$android$exoplayer2$ExoPlayer$EventListener
    at anywheresoftware.b4a.keywords.Common$
    at android.os.Handler.handleCallback(
    at android.os.Handler.dispatchMessage(
    at android.os.Looper.loop(
    at java.lang.reflect.Method.invoke(Native Method)
Caused by: java.lang.ClassNotFoundException:$android$exoplayer2$ExoPlayer$EventListener
    at anywheresoftware.b4j.object.JavaObject.getCorrectClassName(
    at anywheresoftware.b4j.object.JavaObject.createEvent(
    at anywheresoftware.b4j.object.JavaObject.CreateEventFromUI(

I tried it in FillCLV sub and the CreateItem Sub, as I was not exactly sure where to put it.

Am I missing something, because the error says it can't find a class ? I use the 1.52 library.

Thanks for any help.
Upvote 0


Active Member
This works, but I'm getting the same id for each player. What is the best way to give each player a unique id?
So I can pause the correct player.
I can't change playerJ to player1, player2 etc. at least that's what I think.

Thanks for any help.
Upvote 0


Active Member
A Map not I think because the key must be a number, if I use a variable as key it says it cannot assign an empty value.
I was trying some things, but actually it's already a list is it not?
The image + player are both on the clvfront which is added to the clv for each track. If I click on the image then it returns the correct index nr., only the player not.
Also I tried to set the tag with an nr, but that returns only the total.
Upvote 0


Active Member
My trying did not work, so I changed the concept to a single player with separate buttons, now the player itself is not visible, next and previous will load the next track and artwork as image.
Now have to find a solution for alternate fastforward and rewind as I don't know how to handle the Seekto via Java and of course the seekbar, or there must be a way to only show that. Will open a new thread for that.
Upvote 0