开发者

How to get the value of a HTML5 video tag src attribute in Android

开发者 https://www.devze.com 2023-04-03 18:25 出处:网络
My application have a WebView. The WebView HTML has: <video id=\"player\" src=\"rtsp://somesite/videofile.mp4\"开发者_如何转开发 >Video content</video>

My application have a WebView. The WebView HTML has:

<video id="player" src="rtsp://somesite/videofile.mp4"开发者_如何转开发 >Video content</video>

How can I get the src attribute from this HTML?

I want to have the URI of this video. It's needed to play in my video player. I don't want to use VideoView.


You can:

yourWebView.loadUrl("javascript:document.getElementById('player').doSomething..

If you want to get the value out of your WebView, use

/* Register a new JavaScript interface called JSInterface */  
yourWebView.addJavascriptInterface(new MyJavaScriptInterface(), "JSInterface");
yourWebView.loadUrl("javascript:window.JSInterface.setSrc(document.getElementById('player').src)");

setSrc is a method in your Java class.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号