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: 107
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
fullscreen_switchtargetplayerview (java line: 415)
java.lang.ClassCastException: scantech.iptv.b4xpage3 cannot be cast to scantech.iptv.b4xmainpage
at scantech.iptv.fullscreen._switchtargetplayerview(fullscreen.java:415)
at scantech.iptv.fullscreen._activity_create(fullscreen.java:370)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
at scantech.iptv.fullscreen.afterFirstLayout(fullscreen.java:105)
at scantech.iptv.fullscreen.access$000(fullscreen.java:17)
at scantech.iptv.fullscreen$WaitForLayout.run(fullscreen.java:83)
at android.os.Handler.handleCallback(Handler.java:873)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
 
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
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
I forgot to add to manifest from the example. It works now
 
Upvote 0
Top