Android Question Full screen Exoplayer other than MainPage

Scantech

Well-Known Member
Licensed User
Longtime User
B4X:
Private Sub SwitchTargetPlayerView(FullScreenIsDestination As Boolean)
    Dim mp As B4XMainPage = B4XPages.MainPage
    Dim jo As JavaObject
    Dim player As Object = mp.Player.As(JavaObject).GetField("player")
    jo.InitializeStatic("androidx.media3.ui.PlayerView")
    jo.RunMethod("switchTargetView", Array(player, IIf(FullScreenIsDestination, mp.SimpleExoPlayerView1, SimpleExoPlayerView1), IIf(FullScreenIsDestination, SimpleExoPlayerView1, mp.SimpleExoPlayerView1)))
End Sub

I have the media in B4XPage3 Class not B4XMainPage. Erel example is used with B4XMainPage only. Error is in First, Third and Fifth line code. How i set mp to B4XPage3 class?
 

Scantech

Well-Known Member
Licensed User
Longtime User
Here is the attached project. Cant figure this out
 

Attachments

  • Issac IPTV.zip
    19.9 KB · Views: 227
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
B4X:
Private Sub SwitchTargetPlayerView(FullScreenIsDestination As Boolean)
    Dim mp As B4XMainPage = B4XPages.GetPage("Media Player")
    Dim jo As JavaObject
    Dim player As Object = mp.Page3.Player.As(JavaObject).GetField("player")
    jo.InitializeStatic("androidx.media3.ui.PlayerView")
    jo.RunMethod("switchTargetView", Array(player, IIf(FullScreenIsDestination, mp.Page3.SimpleExoPlayerView1, SimpleExoPlayerView1), IIf(FullScreenIsDestination, SimpleExoPlayerView1, mp.Page3.SimpleExoPlayerView1)))
End Sub

Gives me error
 
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
B4X:
Private Sub SwitchTargetPlayerView(FullScreenIsDestination As Boolean)
    Dim mp As B4XPage3 = B4XPages.GetPage("Media Player")
  
    Dim jo As JavaObject
    Dim player As Object = mp.Player.As(JavaObject).GetField("player")
    jo.InitializeStatic("androidx.media3.ui.PlayerView")
    jo.RunMethod("switchTargetView", Array(player, IIf(FullScreenIsDestination, mp.SimpleExoPlayerView1, SimpleExoPlayerView1), IIf(FullScreenIsDestination, SimpleExoPlayerView1, mp.SimpleExoPlayerView1)))
End Sub

The code above fixed it but can't get in full screen for some reason. Its in portrait. If i spend more than 3 hours trying tofigure it out, then ill post another thread.
 
Upvote 0

teddybear

Well-Known Member
Licensed User
The code above fixed it but can't get in full screen for some reason. Its in portrait. If i spend more than 3 hours trying tofigure it out, then ill post another thread.
Try this code, it will set screen orientation to landscape
B4X:
'FullScreen class'
Sub Activity_Create(FirstTime As Boolean)
    If B4XPages.IsInitialized = False Then
        StartActivity(Main)
        Activity.Finish
        Return
    End If
    Activity.LoadLayout("FullScreen")
    Dim j As JavaObject
    j.InitializeContext
    SwitchTargetPlayerView(True)
    j.RunMethod("setRequestedOrientation", Array(0))
    B4XPages.MainPage.Page3.PutLabelInVideoTopRightCorner(SimpleExoPlayerView1, lblExitFullScreen)
End Sub
 
Upvote 0

Scantech

Well-Known Member
Licensed User
Longtime User
I forgot to add to manifest from the example. It works now
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…