I solved the problem using javascript approach. When the HTML page loads, the loadedmetadata event fires when the video metadata is loaded. From now on, you can get the selected video source from the currentSrc attribute of the currentSrc element and transfer it via JavascriptInterface to your own Android code.
Below is the HTML5 video element code. "Android" is the name by which the JavascriptInterface can be obtained in javascript.
<video poster="image/poster.jpg" height="240" width="360" onloadedmetadata="Android.interceptPlay(this.currentSrc);"> <source src="video/BigBuck.m4v"> <source src="video/BigBuck.webm" type="video/webm"> <source src="video/BigBuck.theora.ogv" type="video/ogg"> HTML5 video not supported. </video>
JavascriptInterface Code
private class JavaScriptInterface { Context mContext; JavaScriptInterface(Context c) { mContext = c; } public void interceptPlay(String source) {
Lastly, add a JavascriptInterface to your WebView during action creation
mWebView.addJavascriptInterface(new JavaScriptInterface(this), "Android");
It is important to catch the loadedmetadata event by adding the onloadedmetadata attribute to the HTML5 video element, rather than registering an event listener when the page loads through addEventListener("loadedmetadata",...) , because in a fast network, the loadedmetadata event can be (see http: // dev.opera.com/articles/view/consistent-event-firing-with-html5-video )
source share