Android Question html video

Almora

Well-Known Member
Licensed User
Longtime User
library: WebViewExtras2

I can't capture a screenshot. Where am I making mistakes?
 

Almora

Well-Known Member
Licensed User
Longtime User
I can't add a code to the question. the error in the picture comes out.
 

Attachments

  • Screenshot_20250820-064741_Lemur Browser.jpg
    Screenshot_20250820-064741_Lemur Browser.jpg
    329.2 KB · Views: 34
Upvote 0

Almora

Well-Known Member
Licensed User
Longtime User
didn't happen. i had to zip.
 

Attachments

  • test.zip
    895 bytes · Views: 20
  • test.jpg
    test.jpg
    147.2 KB · Views: 29
Upvote 0

aeric

Expert
Licensed User
Longtime User
You need to add
B4X:
WebViewExtras1.addJavascriptInterface(JavascriptInterface1, "B4A")

For forum posting, "script:" is allowed but you can still write "javascript.:" (no dot) in your code.

B4X:
Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private Button1 As Button
    Private WebView1 As WebView
    Private B4XImageView1 As B4XImageView
    Private WebViewExtras1 As WebViewExtras
    Private JavascriptInterface1 As DefaultJavascriptInterface
End Sub

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

Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("web")
    WebViewExtras1.Initialize(WebView1)
    JavascriptInterface1.Initialize
    WebViewExtras1.addJavascriptInterface(JavascriptInterface1, "B4A")
    WebView1.LoadUrl("https://www.w3schools.com/html/mov_bbb.mp4")
End Sub

Private Sub Button1_Click
    Dim js As String = $"script:(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);
    })();"$
    WebViewExtras1.executeJavascript(js)
End Sub

Public Sub B4ACaptured (data As String )
    Log("got: " & data)
    B4XImageView1.Bitmap = Base64EncodeDecodeImage.Base64StringToImage(data.SubString(23))
End Sub
 
Last edited:
Upvote 0
Top