Android Question How to play SimpleExoPlayer Only one video in xCustomListView, Based on xCLV index?

kangmasjani

Member
Exoplayer in xCustomListView:
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("L_Test")
          
    For Each No As Int In conlectionsMap.Keys   ' <===total line only 7 videos
        Dim titles As String = conlectionsMap.Get(No)
        Dim pan As B4XView = xui.CreatePanel("")
              pan.SetLayoutAnimated(0, 0, 0, 100%x,100%y)
              pan.LoadLayout("L_ExoplayerViews")
                   'Dim SimpleExoPlayerView1 As SimpleExoPlayerView  <=== in Sub Global
                    Dim engin As SimpleExoPlayer
                    engin.Initialize("Player1")
                    engin.Prepare(engin.CreateUriSource( uris&"/"&titles ) )
                        SimpleExoPlayerView1.Player = engin
                        SimpleExoPlayerView1.Tag = engin
                        SimpleExoPlayerView1.UseController = True
        
        xCLV.Add(pan, No )
        
        Log($"No: ${No}, Judul: ${titles"$)
    Next
End Sub
 

kangmasjani

Member
Salah satu solusi yang mungkin untuk ini, adalah membiarkan pengguna mengklik item dan kemudian menampilkan panel di atas daftar dengan ExoPlayer.
Konsep UI saya tidak seperti itu tetapi mirip dengan TikTok, tetapi tidak dengan TikTok karena saya masih belajar b4a, jadi saya hanya menggunakan metode: _VisibleRangeChanged(FirstIndex As Int, LastIndex As Int)

Jadi ketika pengguna menggulir ke bawah, video sebelumnya secara otomatis berhenti dan video berdasarkan kunci FirstVisibleIndex = FirstIndex dimulai.

B4X:
 Root.LoadLayout("L_xCLV")
    Try
        For i = 0 To 6 'koleksiMap.Size -1
            Dim p As B4XView = xui.CreatePanel("")
            p.SetLayoutAnimated(0, 0, 0, xCLV.AsView.Width, xCLV.AsView.Height)
            p.LoadLayout("L_ExoplayerViews")
            xCLV.Add(p, ItemEngine( "players_"&i, koleksiMap.Get(i+1), i ))
        Next
    Menangkap
        xui.MsgboxAsync(LastException, "") ' <==Maaf kesalahan Debuger saya, jadi gunakan saja xui.MsgboxAsync
    Akhir Coba

    Sub Item PribadiEngine(inisial Sebagai String, url Sebagai String, tag Sebagai String ) Sebagai B4XView
        Pemain Redup Sebagai SimpleExoPlayer
        Players.Initialize(inisial)
        Players.Prepare(Players.CreateUriSource(urls ) )
        SimpleExoPlayerView1.Pemain = Pemain
        SimpleExoPlayerView1.Tag = Pemain
            VideoPlayers.Put(tags, Players) '<=== Map'
        Kembali Pemain
    Akhir Sub


    Private Sub xCLV_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
    Try
      
        'Bisakah Anda kode di sini?
         Jika xCLV.FirstVisibleIndex = FirstIndex Maka
              Dim PlayStart As SimpleExoPlayer = VideoPlayers.GetValueAt(FirstIndex) ' <== VideoPlayers Is Engine 
              PlayStart.Mainkan
        Akhiri Jika

      
    Menangkap
        xui.MsgboxAsync(LastException, False)
    Akhir Coba
    Akhir Sub
 
Last edited:
Upvote 0

kangmasjani

Member
One possible solution for this, is to let the user click on an item and then show a panel over the list with ExoPlayer.
My UI concept is not like that but similar to TikTok, but not with TikTok because I'm still learning b4a, so I just use the method: _VisibleRangeChanged(FirstIndex As Int, LastIndex As Int)

So when the user scrolls down, the previous video automatically stops and the video based on the key FirstVisibleIndex = FirstIndex starts.
B4X:
Root.LoadLayout("L_xCLV")
    Try
        For i = 0 To koleksiMap.Size -1
            Dim p As B4XView = xui.CreatePanel("")
            p.SetLayoutAnimated(0, 0, 0, xCLV.AsView.Width,  xCLV.AsView.Height)
            p.LoadLayout("L_ExoplayerViews")
            xCLV.Add(p, ItemEngine( "players_"&i, koleksiMap.Get(i+1), i ))
        Next
    Catch
        xui.MsgboxAsync(LastException, "")
    End Try
    

    Private Sub ItemEngine(inisial As String, urls As String, tags As String ) As B4XView
        Dim Players As SimpleExoPlayer
        Players.Initialize(inisial)
        Players.Prepare(Players.CreateUriSource(urls ) )
        SimpleExoPlayerView1.Player = Players
        SimpleExoPlayerView1.Tag = Players
            VideoPlayers.Put(tags, Players)  '<=== MAP
        Return Players
    End Sub

    Private Sub xCLV_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
    Try
        'Can you help add the code here?

        If xCLV.FirstVisibleIndex = FirstIndex Then
            Dim PlayStart As SimpleExoPlayer = VideoPlayers.GetValueAt(FirstIndex) '<== Map
            PlayStart.Play
        End If
        
    Catch
        xui.MsgboxAsync(LastException, False)
    End Try
    End Sub
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…