
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.

    Private WebView1 As WebView
    Private Button1 As Button
    Dim WebViewExtras1 As WebViewExtras
    Private B4XImageView1 As B4XImageView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("web")
    
    WebViewExtras1.Initialize(WebView1)
    WebViewExtras1.addJavascriptInterface(WebView1,"B4A")
'    WebViewExtras1.addWebChromeClient(WebView1,"")
    WebView1.LoadUrl("https://www.w3schools.com/html/mov_bbb.mp4")
End Sub

Private Sub Button1_Click
    Dim js As String = $"
                        javascript:(function() {
                            const video = document.querySelector('video');
                            const canvas = document.createElement('canvas');
                            canvas.width = video.videoWidth;
                            canvas.height = video.videoHeight;
                            canvas.getContext('2d').drawImage(video, 0, 0);
                            const data = canvas.toDataURL('image/jpeg',100);
                            B4A.CallSub('B4ACaptured',true, data.substring(23));
                        })();
                        "$
    
    WebViewExtras1.executeJavascript(js)
End Sub

Public Sub B4ACaptured(HexImage As String )
    Log("got: " & HexImage)
    B4XImageView1.Bitmap = Base64EncodeDecodeImage.Base64StringToImage(HexImage)
End Sub
Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub