iOS Question [SOLVED] WkWebview autoplay video

Sasuke Sama

Active Member
Licensed User
Any ideas?
B4X:
    Dim no As NativeObject = WKWebView1
    no.RunMethod("mediaTypesRequiringUserActionForPlayback", Array(False))
dosent seem to work
it gives an error
B4X:
Method not found: mediaTypesRequiringUserActionForPlayback, target: <WKWebView: 0x102039e00; frame = (0 0; 375 667); layer = <CALayer: 0x283acd1e0>>
EDIT : Thats how its done

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)
    conf.SetField("mediaTypesRequiringUserActionForPlayback", False)
   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
 
Last edited:
Top