Android Question Access To label & stop video palying when scroll listview

invocker

Active Member
Hi
How can Access To label get value and set value
and how can stop video palying when scroll listview from this project

b4xmainpage code
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
     Private SimpleExoPlayer1 As SimpleExoPlayer
    Dim SimpleExoPlayerView1 As SimpleExoPlayerView
    Dim p As B4XView
    Dim i As Int =0
    Dim lb1 As B4XView
    Dim btn1 As B4XView
 
End Sub
Sub Addstr()
    Dim Links() As String
    Links = Array As String("https://download.samplelib.com/mp4/sample-5s.mp4", "https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4" )


     For Each link As String In Links
        Dim s As Info = B4XPages.GetPage("info1")
        p = xui.CreatePanel("")
        p.Color=Colors.Transparent
        p.SetLayoutAnimated(100,0,0,Root.Width,Root.Height )
        p.LoadLayout("LayVideoPlayer") 
       lb1.Text=Rnd(1,1234)
         btn1.Text="Change" & i
        s.Lvinfo.Add(p,"")   
        SimpleExoPlayer1.Initialize("SimpleExoPlayer1")
        SimpleExoPlayer1.Prepare(SimpleExoPlayer1.CreateUriSource(link))
        SimpleExoPlayerView1.Player = SimpleExoPlayer1
         i=i+1
    Next
 
End Sub
Private Sub BtnShowVideo_Click
    Dim info1 As Info
    info1.Initialize
    B4XPages.AddPage("info1",info1)
    B4XPages.ShowPage("info1")
    Addstr
    
End Sub
Private Sub btn1_Click
    
    ' hier I can not acces to lb1  to get value and add a value to it from btn 1
    
    
    
'    Dim lb As Label =Sender
'    Dim x As Int =lb.Text
    Dim btn As Button =Sender
    Dim x As Int =lb1.Text
    x=x+1
    btn.Text="change "& x
End Sub

info code


B4X:
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
    Dim Lvinfo As CustomListView
    
End Sub

'You can add more parameters here.
Public Sub Initialize As Object
    Return Me
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    'load the layout to Root
    Root.LoadLayout("Layinfo")
End Sub
 

Attachments

  • Project.zip
    17.6 KB · Views: 201

invocker

Active Member
I create new b4xpage named form1 and again

can't acces with this code too



B4X:
Dim s As form1 = B4XPages.GetPage("form")
    Dim btn As Button =Sender
    Dim x As Int =s.lb1.Text
    x=x+1
    btn.Text="change "& x
    s.lb1.Text=btn.Text
 
Upvote 0

invocker

Active Member
I add a click event for label , maybe can access but when click on button i get last label text How can resolve this ,I don't need a click event for label I want to get the first label text when click a first button and the next label text when click then next button and next step th same

B4X:
Sub Addstr()
    Dim Links() As String
    Links = Array As String("https://download.samplelib.com/mp4/sample-5s.mp4", "https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4" )
    For Each link As String In Links
        Dim s As Info = B4XPages.GetPage("info1")
        p = xui.CreatePanel("")
        p.Color=Colors.Transparent
        p.SetLayoutAnimated(100,0,0,Root.Width,Root.Height )
        p.LoadLayout("LayVideoPlayer")
        lb1.Text=i
        lb1.Tag=i
        lb1_Click
         btn1.Text="Change" & i
        s.Lvinfo.Add(p,"")
        SimpleExoPlayer1.Initialize("SimpleExoPlayer1")
        SimpleExoPlayer1.Prepare(SimpleExoPlayer1.CreateUriSource(link))
        SimpleExoPlayerView1.Player = SimpleExoPlayer1
         i=i+1
    Next
 End Sub

Private Sub BtnShowVideo_Click
    Dim info1 As Info
    info1.Initialize
    B4XPages.AddPage("info1",info1)
    B4XPages.ShowPage("info1")
    Addstr
End Sub
 
Private Sub btn1_Click
 
    ' hier I can not acces to lb1  to get value and add a value to it from btn 1
'and how can stop video play one scroll the listview
 
 
'    Dim lb As Label =Sender
'    Dim x As Int =lb.Text
    Dim btn As Button =Sender
    btn.Text=lb1.text
Log(Sender)
 
End Sub

Private Sub lb1_Click
    lb=Sender
End Sub
 
Upvote 0

invocker

Active Member
this what happen
 

Attachments

  • Untitled.png
    Untitled.png
    354.9 KB · Views: 154
Upvote 0

teddybear

Well-Known Member
Licensed User
Hi
How can Access To label get value and set value
and how can stop video palying when scroll listview from this project

b4xmainpage code
B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
     Private SimpleExoPlayer1 As SimpleExoPlayer
    Dim SimpleExoPlayerView1 As SimpleExoPlayerView
    Dim p As B4XView
    Dim i As Int =0
    Dim lb1 As B4XView
    Dim btn1 As B4XView
 
End Sub
Sub Addstr()
    Dim Links() As String
    Links = Array As String("https://download.samplelib.com/mp4/sample-5s.mp4", "https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4" )


     For Each link As String In Links
        Dim s As Info = B4XPages.GetPage("info1")
        p = xui.CreatePanel("")
        p.Color=Colors.Transparent
        p.SetLayoutAnimated(100,0,0,Root.Width,Root.Height )
        p.LoadLayout("LayVideoPlayer")
       lb1.Text=Rnd(1,1234)
         btn1.Text="Change" & i
        s.Lvinfo.Add(p,"")  
        SimpleExoPlayer1.Initialize("SimpleExoPlayer1")
        SimpleExoPlayer1.Prepare(SimpleExoPlayer1.CreateUriSource(link))
        SimpleExoPlayerView1.Player = SimpleExoPlayer1
         i=i+1
    Next
 
End Sub
Private Sub BtnShowVideo_Click
    Dim info1 As Info
    info1.Initialize
    B4XPages.AddPage("info1",info1)
    B4XPages.ShowPage("info1")
    Addstr
   
End Sub
Private Sub btn1_Click
   
    ' hier I can not acces to lb1  to get value and add a value to it from btn 1
   
   
   
'    Dim lb As Label =Sender
'    Dim x As Int =lb.Text
    Dim btn As Button =Sender
    Dim x As Int =lb1.Text
    x=x+1
    btn.Text="change "& x
End Sub

info code


B4X:
Sub Class_Globals
    Private Root As B4XView 'ignore
    Private xui As XUI 'ignore
    Dim Lvinfo As CustomListView
   
End Sub

'You can add more parameters here.
Public Sub Initialize As Object
    Return Me
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    'load the layout to Root
    Root.LoadLayout("Layinfo")
End Sub
I guess you want 2 pages to show video separately, but you Initialized only one page instance and added LayVideoPlayer panel twice on the page. the currently displayed page is generated in the first step,but current lb1.text you want to get and set value is 2nd step. so you could not get and set it.
you should create 2 page instances or 2 exoplayer components to play the videos. when the question is solved, 2nd issue stop video palying will be also ok.
 
Upvote 0

invocker

Active Member
thank's For replay I can access to The all buttons Created using sender object like this

B4X:
dim btn as button=sender
dim s as string =btn.text
log(s)
I get each btn text and can change it ,so i need a similar then button with label , maybe use tag option like id to access on it
 
Upvote 0

invocker

Active Member
I resolve it with CSBuilder create button with img and text now I have problem with stop video playing where scrol the view
 
Upvote 0

teddybear

Well-Known Member
Licensed User
I resolve it with CSBuilder create button with img and text now I have problem with stop video playing where scrol the view
It is same issue as you accessing label, you use only one SimpleExoPlayer to create 2 player instances,
SimpleExoPlayer1.Initialize("SimpleExoPlayer1")
when scroll event is fired, you can only get the first video player handle, so it will not stop the 2nd video playing.
The correct way is that store all of SimpleExoPlayer instances to a list when you initialize them. then get them all to pause video playing in scroll event.
 
Upvote 0

teddybear

Well-Known Member
Licensed User
can you change the zip source for me please for understand correct

I have commented them in your code.

1.Define a list for player
B4X:
Sub Class_Globals
    ...
    Dim lb1 As B4XView
    Dim btn1 As B4XView
    Dim PlayerList as List '<==It's for storing player handle
End Sub

2. Add player handle to list in Sub Addstr()
B4X:
Sub Addstr()
    PlayList.initilize  '<==
    Dim Links() As String
    Links = Array As String("https://download.samplelib.com/mp4/sample-5s.mp4", "https://www.learningcontainer.com/wp-content/uploads/2020/05/sample-mp4-file.mp4" )
    For Each link As String In Links
        Dim s As Info = B4XPages.GetPage("info1")
        Dim YourPlayer As  SimpleExoPlayer   '<==Here use local var for player
        p = xui.CreatePanel("")
        p.Color=Colors.Transparent
        p.SetLayoutAnimated(100,0,0,Root.Width,Root.Height )
        p.LoadLayout("LayVideoPlayer")
        lb1.Text=i
        lb1.Tag=i
        lb1_Click
         btn1.Text="Change" & i
        s.Lvinfo.Add(p,"")
        YourPlayer.Initialize("SimpleExoPlayer1")   '<==
        YourPlayer.Prepare(YourPlayer.CreateUriSource(link)) '<==
        SimpleExoPlayerView1.Player = YourPlayer '<==
        PlayerList.add(YourPlayer)   ' Here store player to List
         i=i+1
    Next
    ' Note:If PlayerLIst is used in other class, here you should assign it to a Process Globals Variable
   '  Process_Globals_Variable = PlayerList

 End Sub

3. Process event
B4X:
Sub SomeEvent       'You want to do in your event
    for i = 0 to PlayerList.size-1
        PlayerList.get(i).As(SimpleExoPlayer).pause    '<==if Sub is in B4XMainPage
   ' Process_Globals_ariable.get(i).As(SimpleExoPlayer).pause  '<==Some class else
    Next
End Sub
 
Last edited:
Upvote 0
Top