首页 > 解决方案 > 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");

标签: androidandroid-webview

解决方案


我在 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 );
    }

推荐阅读