php - Android App 正在通过 Webview URL 加载视图,但未加载 URL 在后台的音频
问题描述
我有一个 Android 应用程序通过 Webview Url 加载视图。Url 中有一个背景音频。Url 正在正确加载,但未播放音频。
这是我在 html 中播放音频的 HTML 代码。
@if($booking->order_status == "Pending")
<audio autoplay>
<source src="notification/tune.mp3">
</audio>
@endif
以及运行此音频的 javascript 部分。
<script>
window.onload = function() {
var context = new AudioContext();
}
</script>
任何人都可以帮助我在我的 android 应用程序代码中添加什么,以便在使用 Webview 加载 URL 时在后台运行音频。
谢谢你。
解决方案
将此设置添加到 webview 对象
WebView myWebView = (WebView) findViewById(R.id.webview);
WebSettings webSettings = myWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setMediaPlaybackRequiresUserGesture(false)
推荐阅读
- scrapy-splash - Scrapy Splash 需要永远渲染一个网站
- python - f 字符串格式打印中的浮点数精度
- javascript - ApolloClient: Invariant Violation 1 – 正确设置 apollo 客户端
- postgresql - 我需要一个函数来从表中选择 88 个随机行(不重复)
- keycloak - 我如何使用 keycloak 验证 jbpm 7.24
- flutter - Twitter 应用程序加载 我如何做颤动的应用程序?
- mysql - 如何创建一个返回最高 id 的函数?
- python - 忽略python中的转义字符
- c# - Unity 仅检测图像碰撞 OnEndDrag
- reactjs - Routes.push() 在 NextJS 中没有按预期工作