Online audio streaming websites are not working pr

2020-07-22 17:44发布

问题:

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