简体   繁体   中英

HTML5 Audio not working on Crosswalk Cordova or standard Cordova based WebView on Android 4.4

I am trying to use the HTML Audio API to play a mp3 file from a remote HTTP source. Its flat out not working on either Android's default WebView based Cordova instance or using a Crosswalk Cordova blink based instance. The device is registering it as playing but no actual sound is emitted.

var audio = new Audio();


function playSong(url) {

    audio.src = url;
    audio.play();
}

The code above is a snippet with all the non-audio related stuff stripped out, i have the internet permission set added and the app works as hoped on the desktop (using Chrome 35).

Is it the case that i am missing a permission for playback or does there need to be a physical audio tag present on the page for it to work?

I see that you ended up going Native, but I'll answer with what solved my problem. I was trying to make an HTML5 game with music that ran on Android 4.4, but it never worked. I have tried many things, and have been having this problem for months.

First off, Crosswalk's minimum Android version is 4.0 right now.

My issue was that I wasn't actually using Crosswalk. I think I was using it at some point, then switched computers and the plugin dependency wasn't saved to my config.xml. Anyways, something got mixed up, and it wasn't being included in my build. By default, crosswalk builds an arm and x86 .apk files , I was only getting one. My apk also was only about 20.3MB , after fixing this it jumped to ~42MB (I think, somewhere around there).

After properly including XWalk, HTML5 audio worked and my game ran EXTREMELY more smoothly on Android 4.4. This is due to improved rendering tech on the new chromium browser.

The Fix

cordova plugin remove cordova-plugin-crosswalk-webview
#delete mentions of 'xwalk' from config.xml
cordova plugin add cordova-plugin-crosswalk-webview --save #ensure plugin gets saved to config.xml

Build again. If still not working (no arm and x86 apks, apks still small), delete old apk's in build/output dir, and build again

It should be an auto play issue of Chrome WebView, see here Android KitKat (4.4) video autoplay does not work anymore in webview

But for Crosswalk, the auto play has already been enabled by default, just double checked your sample with the latest Crosswalk binary, it works fine. https://download.01.org/crosswalk/releases/crosswalk/android/canary/8.36.165.0/arm/crosswalk-cordova-8.36.165.0-arm.zip

Did you tried to manually add

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

in the AndroidManifest.xml?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM