Android Question Issue with Fullscreen Video in UltimateWebView2 library

Mattiaf

Active Member
Licensed User
I'm trying to enable the fullscreen mode for video players on various websites using Ivica Golubovic's "UltimateWebView2" library in B4A. Here's the code I'm using:

B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private Settings As WebSettings
    Private CookieM As CookieManager
    Private WebViewClient As UltimateWebViewClient
    Private WebChromeClient As UltimateWebChromeClient

    Public WebView1 As WebView ' Object added through Designer
End Sub

Public Sub Initialize
    ' B4XPages.GetManager.LogEvents = True
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
   
    WebViewClient.Initialize2("WebView1", WebView1)
    WebChromeClient.Initialize2("WebView1", WebView1).AllowFullScreenVideo(True, False) 'AllowFullScreenVideo only if you need, it is not necessary to set.
   
    Settings.Initialize(WebView1)
    CookieM.Initialize(WebView1)
   
    Settings.AllowContentAccess = True
    Settings.AllowFileAccess = False
    Settings.AllowFileAccessFromFileURLs = False
    Settings.AllowUniversalAccessFromFileURLs = True
    Settings.BuiltInZoomControls = False
    Settings.JavaScriptEnabled = True
    Settings.DomStorageEnabled = True
    Settings.JavaScriptCanOpenWindowsAutomatically = False
    Settings.MediaPlaybackRequiresUserGesture = False
    Settings.SaveFormData = True
    Settings.GeolocationEnabled = False
    Settings.SupportMultipleWindows = True
    CookieM.AcceptCookies = True
    CookieM.AcceptFileSchemeCookies = True
    CookieM.AcceptThirdPartyCookies = False
    WebView1.LoadUrl("https://www.animesaturn.in/")
End Sub

Private Sub WebView1_CreateWindow (OverridenRequest As WebResourceRequest, ChildWebView As WebView, IsDialog As Boolean, IsUserGesture As Boolean) As Boolean 'Works from API level 1 and above. Return True if you want to consume ChildWebView, False to destroy. SupportMultipleWindows option must be enabled. You can add the newly created WebViewObject to Layout manualy, or use UltimateWebView's AddChildWindow method.
    Log("WebkitWebView1_CreateWindow")
    If IsUserGesture = False Then Return False 'Try to prevent an unwanted commercial popup's.
    Return True
End Sub

However, if I set #SupportedOrientations: portrait, the video, once I click on the fullscreen button, will be displayed in portrait mode regardless of whether I switch the screen orientation to landscape from the phone's dropdown menu. On the other hand, if I set #SupportedOrientations: landscape, everything will be displayed in landscape mode even if my phone is in portrait orientation. Also, the library print at debug a log where it says to set either landscape or portrait, thus unspecified, which would be great for me, isn't supported :( . . This is quite a headache, and I can't seem to find a solution. The library "should" handle fullscreen video in this manner for online videos. The issue occurs regardless of the video player.
Unfortunately I' havent been able to implement SoftOrientation Library not because it's difficult or what, but because of the moltitude of cases and I don't know which code suits mostmy case scenario.
Any suggestions on how to resolve this orientation issue while keeping fullscreen video functional?

Thanks in advance!
 
Last edited:

Mattiaf

Active Member
Licensed User
Anyone could help ? Cant believe such a "silly" thing is kinda impossible to do without a 3rd party lib...
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
B4X:
Settings.UseWideViewPort = True
?
 
Upvote 0

Ivica Golubovic

Active Member
Licensed User
The problem is that when the orientation changes, the webview is forced to redraw itself, which causes the previous state to be reset. The UltimateWebView2 library is not intended to deal with screen orientation issues. One of the potential solutions is SoftOrientation or any other way that solves the problems that arise when changing the orientation.
 
Upvote 0

Mattiaf

Active Member
Licensed User
The problem is that when the orientation changes, the webview is forced to redraw itself, which causes the previous state to be reset. The UltimateWebView2 library is not intended to deal with screen orientation issues. One of the potential solutions is SoftOrientation or any other way that solves the problems that arise when changing the orientation.
Hi Ivica, I really appreciated your answer but sadly I can read it only now.
The issue is that, as I specified on my first post, I already checked Soft Orientation, but I dont really know how to make it work for my scenario. I feel like dumb having this issue more than a year so far.

To be honest, this is the Code i wrote so far, it seems to "WORK" which means it does what I'm looking for, but not sure if it might considered as "good"

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private xui As XUI
End Sub

Sub Globals
    Private ime1 As IME
    Private WebView1 As WebView
    Private ActivityParent As JavaObject
End Sub

Sub Activity_Create(FirstTime As Boolean)
    WebView1.Initialize("WebView1")
    Activity.AddView(WebView1, 0, 0, 100%x, 100%y)
    ime1.Initialize("ime1")
    ime1.AddHeightChangedEvent
    WebView1.LoadUrl("https://www.animesaturn.in/")
    Dim jo As JavaObject = Activity
    jo.RunMethodJO("getContext", Null).RunMethodJO("getWindow", Null).RunMethod("setSoftInputMode", _
     Array As Object(0x20))
    ActivityParent = jo.RunMethodJO("getParent", Null)
End Sub
Sub IME1_HeightChanged (NewHeight As Int, OldHeight As Int)
    CallSubDelayed(Me, "AfterChange")
End Sub

Sub AfterChange
    Dim ajo As Panel = Activity
    Dim width As Int = ActivityParent.RunMethod("getMeasuredWidth", Null)
    Dim height As Int = ActivityParent.RunMethod("getMeasuredHeight", Null)
    If width = 0 Or height = 0 Then Return
    ajo.Width = width 'update the "activity" width and height
    ajo.Height = height
    WebView1.Width = width
    WebView1.Height = height
End Sub

Sub Activity_Resume
    AfterChange
End Sub
 
Upvote 0
Top