Online audio streaming websites are not working properly on WebView

為{幸葍}努か 提交于 2019-12-06 08:27:29

问题


I try to play online audio songs from online audio streaming websites like gaana.com or saavn.com etc. on WebView.

My Code:

WebView webView = findViewById(R.id.webView);
webView.setWebViewClient(new WebViewClient());
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.loadUrl("https://gaana.com/");

Websites are loaded in webview correctly but the problem is that when I click on play(for any song) nothing will happen. i.e, no any response show in webview.

My manifest file:

<manifest package="biz.coolpage.aashish.app"
          xmlns:android="http://schemas.android.com/apk/res/android">

    <uses-permission android:name="android.permission.INTERNET"/>

    <application
        android:allowBackup="false"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <activity
            android:name="biz.coolpage.aashish.app.MainActivity"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.Translucent.Light">
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
            <meta-data android:name="android.webkit.WebView.EnableSafeBrowsing"
                android:value="true" />
        </activity>

    </application>

</manifest>

Thanks for help guys in advance.


回答1:


Try to add android:hardwareAccelerated="true" into activity tag in manifest. And then add code:

    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://gaana.com");

https://developer.android.com/guide/topics/graphics/hardware-accel.html



来源:https://stackoverflow.com/questions/49096824/online-audio-streaming-websites-are-not-working-properly-on-webview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!