5

I have the task to record user activity in a webview, in other words I need to create an mp4 video file while the user navigates in a webview. Pretty challenging :) I font that in Android 4.3 introduced MediaCodec : was expanded to include a way to provide input through a Surface (via the createInputSurface method). This allows input to come from camera preview or OpenGL ES rendering. I even find an example where you could record a game written in opengl : http://bigflake.com/mediacodec/

My question is : how could I record a webview activity ? I assume that If I could draw the webview content to opengl texture, than everything would be fine. But I don't know how to do this.

Can anybody help me on this?

Paul Verest
  • 60,022
  • 51
  • 208
  • 332
Szabo Barna
  • 107
  • 1
  • 3
  • One approach is to create a virtual display and capture the output. As of Android 4.3, however, you would need to use non-public native APIs to do this. – fadden Sep 25 '13 at 17:08
  • Android 4.4 introduced a screenrecord feature for developers (see http://developer.android.com/about/versions/kitkat.html#44-screen-recording). Source is here: https://android.googlesource.com/platform/frameworks/av/+/kitkat-release/cmds/screenrecord/screenrecord.cpp – fadden Oct 31 '13 at 22:42

2 Answers2

0

Why not try WebView.onDraw first, instead of using OpenGL? The latter approach may be more complicated, and not supported by all devices.

Once you will be able to obtain the screenshots, then you can create the video (to create video from image sequence on android), a separate task where mediacodec should help.

Community
  • 1
  • 1
Paul Verest
  • 60,022
  • 51
  • 208
  • 332
0

"I assume that If I could draw the webview content to opengl texture".

It is possible.

The SurfaceTexture is basically your entry point into the OpenGL layer. It is initialized with an OpenGL texture id, and performs all of it's rendering onto that texture.

The steps to render your view to opengl:

1.Initialize an OpenGL texture

2.Within an OpenGL context construct a SurfaceTexture with the texture id. Use SurfaceTexture.setDefaultBufferSize(int width, int height) to make sure you have enough space on the texture for the view to render.

3.Create a Surface constructed with the above SurfaceTexture.

4.Within the View's onDraw, use the Canvas returned by Surface.lockCanvas to do the view drawing. You can obviously do this with any View, and not just WebView. Plus Canvas has a whole bunch of drawing methods, allowing you to do funky, funky things.

The source code can be found here: https://github.com/ArtemBogush/AndroidViewToGLRendering And you can find some explanations here:http://www.felixjones.co.uk/neo%20website/Android_View/

dragonfly
  • 1,151
  • 14
  • 35