I'm trying to draw a WebView on SurfaceTexture so I can render it in OpenGL.
So far, I successfully played youtube video in WebView the standard way:
...
webView.getSettings().setJavaScriptEnabled(true);
if (Build.VERSION.SDK_INT < 8)
{
webView.getSettings().setPluginsEnabled(true);
}
else
{
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
}
webView.setWebChromeClient(new WebChromeClient() { });
webView.setWebViewClient(new WebViewClient());
...
also the hardware acceleration is turned on:
<application
android:hardwareAccelerated="true"
...
And I also successfully rendered the WebView in OpenGL (except playing the video) based on this tutorial: http://anuraagsridhar.wordpress.com/2013/03/13/rendering-an-android-webview-or-for-that-matter-any-android-view-directly-to-opengl/
Additional initialization of the WebView (so it is always 'portrait' and fits into the texture):
Point p = new Point();
activity.getWindow().getWindowManager().getDefaultDisplay().getSize(p);
webView.setLayoutParams(new ViewGroup.LayoutParams(p.x, p.y));
surfaceTexture.setDefaultBufferSize(p.x, p.y);
Overriden onDraw method of the WebView:
@Override
public void onDraw(Canvas c)
{
try
{
Point p = new Point();
activity.getWindow().getWindowManager().getDefaultDisplay().getSize(p);
Canvas canvas = surfaceTexture.lockCanvas(new Rect(0,0,p.x,p.y));
canvas.save();
canvas.translate(-scrollL, -scrollT);
super.onDraw(canvas);
canvas.restore();
surfaceTexture.unlockCanvasAndPost(canvas);
}
catch (Surface.OutOfResourcesException e)
{
throw new RuntimeException(e);
}
}
When trying to play YouTube video on webview rendered using the above hack, the video rectangle is black (however the sound can be heard). I suspect that the hardware acceleration does not work on surface texture.
So the question is: Is there any way to play a youtube video on OpenGL texture?