如何在 Android 中获取 HTML5 视频标签 src 属性的值

发布于 2024-12-03 15:21:25 字数 240 浏览 0 评论 0原文

我的应用程序有一个 WebView。 WebView HTML 具有:

<video id="player" src="rtsp://somesite/videofile.mp4" >Video content</video>

如何从此 HTML 获取 src 属性?

我想要这个视频的 URI。它需要在我的视频播放器中播放。我不想使用 VideoView。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉墨 2024-12-10 15:21:25

您可以:

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

如果您想从 WebView 中获取值,请使用

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

Java 类中的 setSrc 方法。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文