Nabin
Nabin

Reputation: 11786

Cannot play audio tag in WebView: Android Lollipop

It's been hours, and still I cannot get anything on the topic. I searched a lot, still there is no help.

What I have done so far (of course this is not only what I have tried) which looks obvious, is as below:

AndroidManifest.xml

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

MainAcitivity:

WebView webMain = (WebView) findViewById(R.id.my_web_view);

        webMain.loadUrl("file:///android_asset/testing.html");
        webMain.setWebViewClient(new MyWebViewClient(getApplication()));

activity_main:

<WebView xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/my_web_view"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/app_bar" />

I can see the following but no sound is played:

enter image description here

Logcat:

02-12 10:06:53.535    6392-6429/org.example.android.flickrbrowser E/MediaResourceGetter﹕ Unable to configure metadata extractor
02-12 10:08:59.400    6492-6529/org.example.android.flickrbrowser D/MediaResourceGetter﹕ ethernet/wifi connection detected
02-12 10:09:08.114    6492-6529/org.example.android.flickrbrowser D/MediaResourceGetter﹕ resource doesn't have video

Any help or some link is appreciated. Thank you so much

EDIT

testing.html

This file contains the <audio> tag of html

<audio style="margin-top:20px; padding-left: 10px;" title="Thing" src="http://someipaddress:port/;" controls="controls" autoplay=""></audio>

Upvotes: 4

Views: 2240

Answers (2)

Jos&#233; Maia
Jos&#233; Maia

Reputation: 97

That is enough to me

webMain.getSettings().setJavaScriptEnabled(true); webMain.getSettings().setMediaPlaybackRequiresUserGesture(false);

Upvotes: 4

Max
Max

Reputation: 529

Make your main activity next

MainAcitivity:

WebView webMain = (WebView) findViewById(R.id.my_web_view);
        webMain.setWebViewClient(new MyWebViewClient());
        webMain.getSettings().setJavaScriptEnabled(true);
        webMain.getSettings().setMediaPlaybackRequiresUserGesture(false);
        webMain.setWebChromeClient(new WebChromeClient());
        webMain.loadUrl("file:///android_asset/testing.html");

To Manifest add:

android:hardwareAccelerated="true"

Upvotes: -1

Related Questions