Android Question capture video screenshot in webview

Almora

Active Member
Licensed User
Longtime User
hi..
I am playing video in webview. when i take a screenshot it turns black. Does this mean that you can't capture screenshots in videos?

B4X:
          ......................

        Bmp.Initialize3(WebViewExtras1.CaptureBitmap)
       
        Dim Out As OutputStream
        Out = File.OpenOutput(dir, "image.png", False)
        WebViewExtras1.CaptureBitmap.WriteToStream(Out, 100, "
         Out.Close
        ............................
 

Attachments

  • Screenshot_20211231-093534.png
    Screenshot_20211231-093534.png
    336.6 KB · Views: 138
  • Screenshot_20211231-093540.png
    Screenshot_20211231-093540.png
    44.7 KB · Views: 168
Last edited:

drgottjr

Expert
Licensed User
Longtime User
here is 1 solution. for whatever reason, it was easier for me to do it this
way. it took 5 minutes to find the snippets in my tool box for cobbling
together.

i chose to capture the image as a jpg. should work for a .png. probably
even better and faster for a .webp.

you need webviewextras to excecute the javascript. you should also
add webviewextra's chromeclient (for possible debugging). i chose to
use marco romo's base64encodedecode library. i was curious about it.
you can roll your own or search for something in the forum.

i chose to skip over saving the bitmap to file. you can put that back in.

should be clear. worked for me. sample image attached showing webview
screen capture under the "capture" button. you can resize to suit.

am also attaching my version of your zipped archive.
 

Attachments

  • capture.png
    capture.png
    86.3 KB · Views: 159
  • web2.zip
    9 KB · Views: 129
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
I just did a few updates.

the javascripts subroutine is the one that performs the task of capturing the video frame to canvas (png or jpg).

If you want to improve or add other options to the video, see this:

and
1640996996327.png
 

Attachments

  • webnew2.zip
    9.1 KB · Views: 168
Last edited:
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
If you use an emulator it may happen that you do not see the video, try it on real phones:
1640993895527.png
 
Last edited:
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
I am attaching the web demo in case you want to migrate to other platforms (Jserver, B4j, B4i).
1640994947940.png
 

Attachments

  • video_screenshot-web.zip
    1.8 KB · Views: 124
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
if you ran my example, that couldn't have happened. so i'm guessing you forgot to copy and paste correctly. it looks like you forgot:
B4X:
    wvx.addJavascriptInterface(WebView1,"B4A")

doesn't have to be "B4A"; that's just the convention we use. whatever it is, it has to be the same in the snippet above AND in the javascript snippet.
for simplicity, we use "B4A".
 
Upvote 0
Top