android - Http stream does not work on Android webview
问题描述
This doesn't work when I want to play a radio with http in Android webview. It works when I play a radio with https. The strange thing is that I uploaded the url of the http stream radio with webview.loadUrl ("x"). I am using standard webview client and chrome client. Can you tell us why this is the problem? I don't see an error or warning in the logcat.
Here are the radios I want to run:
<div id="player_listing"> <div class="radio_element sub_list_item" data="https://ice31.securenetsystems.net/NOGOUM"><div class="sub_list_name">راديو نجوم اف ام</div></div><div class="radio_element sub_list_item" data="http://9090streaming.mobtada.com/9090FMEGYPT"><div class="sub_list_name">راديو 9090</div></div><div class="radio_element sub_list_item" data="http://streaming.radionomy.com/MarocMusic"><div class="sub_list_name">راديو مغربي</div></div><div class="radio_element sub_list_item" data="https://eu8.fastcast4u.com/proxy/90sfm?mp=/1"><div class="sub_list_name">راديو منوعات</div></div><div class="radio_element sub_list_item" data="http://192.99.8.192:3350/;stream.mp3"><div class="sub_list_name">راديو اغاني</div></div> </div>
https ones definitely work but http ones don't work. The website has https protocol.
I have enabled hardware usage in my Android Manifest file.
Activity:
WebView webView = findViewById(R.id.webview);
webView.setWebViewClient(new WebViewClient());
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setAllowContentAccess(true);
webSettings.setDomStorageEnabled(true);
webView.loadUrl("https://myurl.com");
解决方案
我在 6 个月前问过这个问题并找到了解决方案。我忘记在这里写了,我今天又需要它。我希望它可以帮助别人。只需添加下面的 3 行代码。就这些 !!!这样,网站上运行的“http”和“https”流广播就可以工作了。
webview.getSettings().setUserAgentString("Mozilla/5.0 (Linux; Android 4.4; Nexus 5 Build/_BuildID_) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/30.0.0.0 Mobile Safari/537.36");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
LiveWebView.getSettings().setMixedContentMode( WebSettings.MIXED_CONTENT_ALWAYS_ALLOW );
}
推荐阅读
- mobile - 无论手指在虚幻中的位置如何,同时调用捏和旋转事件?
- java - 如何从 postgres db 打印 Java 中的时间戳值?
- ksh - 调用函数时陷阱未激活
- php - 如何将 php 文件导入控制器并收集数据
- django - name_file/Scripts/activate 'name_file' 未被识别为内部或外部命令、可运行程序或批处理文件 windows 10
- android - 在 Kotlin XML 中使用 DataBinding 连接本地化字符串和动态字符串
- python - 从 Python 中的 __str__ 方法返回 int
- linq - 编写 LINQ 尝试创建一个在 C# 程序中运行的 LINQ
- asp.net-core - ODP.NET Core - 脚手架数据库上下文
- gnuplot - 对于 Gnuplot 5.2,如何将 gnuplot 极坐标限制在 180 度范围内?