iOS Question WKWebView and allowsInlineMediaPlayback property?

sidrol

New Member
Licensed User
Longtime User
Hi.
I want to use the WKWebView for a project, but I also need to be able to play videos inside webpages, not full screen.
In the old WebView I could set a NativeObject field as this:
Dim no As NativeObject = WebView1
no.SetField("allowsInlineMediaPlayback", True)

But with the new WKWebView this doesn't work, it seems like this setting is behind some config (https://developer.apple.com/documentation/webkit/wkwebviewconfiguration) Anyone have a clue how to manage this with WKWebView?

--
Thomas
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Example:
B4X:
Sub Process_Globals
   Public App As Application
   Public NavControl As NavigationController
   Private Page1 As Page
   Private WKWebView1 As WKWebView
End Sub

Private Sub Application_Start (Nav As NavigationController)
   'SetDebugAutoFlushLogs(True) 'Uncomment if program crashes before all logs are printed.
   NavControl = Nav
   Page1.Initialize("Page1")
   NavControl.ShowPage(Page1)
   Page1.RootPanel.Color = Colors.White
   WKWebView1 = CreateWKWebView(Page1.RootPanel)
   WKWebView1.LoadUrl("https://www.b4x.com/etp.html")
End Sub

Sub CreateWKWebView (pnl As Panel) As View
   Dim conf As NativeObject
   conf = conf.Initialize("WKWebViewConfiguration").RunMethod("new", Null)
   conf.SetField("allowsInlineMediaPlayback", True)
   Dim wk As NativeObject
   Dim p As NativeObject = pnl
   wk = wk.Initialize("WKWebView").RunMethod("alloc", Null)
   wk.RunMethod("initWithFrame:configuration:", Array(p.RunMethod("frame", Null), conf))
   pnl.AddView(wk, 0, 0, pnl.Width, pnl.Height)
   Return wk
End Sub

Private Sub Page1_Resize(Width As Int, Height As Int)
   Dim v As View = WKWebView1
   v.SetLayoutAnimated(0, 1, 0, 0, Width, Height)
End Sub

I don't see any difference in the behavior.
 
Upvote 0

sidrol

New Member
Licensed User
Longtime User
Thank you! This worked perfectly for me!

Also, now I understand more how to invoke core functionality :)

--
Thomas
 
Upvote 0
Top