I am trying to draw a WebView on a SurfaceTexture so that I can render it in OpenGL.
So far, I have successfully played youtube videos in WebView in a 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()); ...
hardware acceleration is also included:
<application android:hardwareAccelerated="true" ...
And I also successfully rendered WebView in OpenGL (excluding video playback) 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 WebView (so it is always a "portrait" and fits into the texture):
Point p = new Point(); activity.getWindow().getWindowManager().getDefaultDisplay().getSize(p); webView.setLayoutParams(new ViewGroup.LayoutParams(px, py)); surfaceTexture.setDefaultBufferSize(px, py);
Change the onDraw method for 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,px,py)); canvas.save(); canvas.translate(-scrollL, -scrollT); super.onDraw(canvas); canvas.restore(); surfaceTexture.unlockCanvasAndPost(canvas); } catch (Surface.OutOfResourcesException e) { throw new RuntimeException(e); } }
When you try to play a YouTube video on a web view made using the above hack, the rectangle of the video is black (but you can hear the sound). I suspect that hardware acceleration does not work with surface texture.
So the question is: Is there a way to play YouTube videos using OpenGL texture?