简体   繁体   English

HTML5音频无法在Crosswalk Cordova或Android 4.4上基于标准Cordova的WebView上运行

[英]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. 我正在尝试使用HTML Audio API从远程HTTP源播放mp3文件。 Its flat out not working on either Android's default WebView based Cordova instance or using a Crosswalk Cordova blink based instance. 它完全无法在基于Android的默认基于WebView的Cordova实例或基于Crosswalk Cordova闪烁的实例上运行。 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). 上面的代码是一个片段,其中删除了所有与音频无关的内容,我添加了Internet权限集,并且该应用程序可以在桌面上正常运行(使用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. 我看到您最终选择了Native,但我将以解决我的问题的方式回答。 I was trying to make an HTML5 game with music that ran on Android 4.4, but it never worked. 我试图用在Android 4.4上运行的音乐制作HTML5游戏,但从未成功。 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. 首先,Crosswalk的最低Android版本目前为4.0

My issue was that I wasn't actually using Crosswalk. 我的问题是我实际上并没有使用Crosswalk。 I think I was using it at some point, then switched computers and the plugin dependency wasn't saved to my config.xml. 我想我在某个时候正在使用它,然后切换了计算机,而插件依赖项没有保存到我的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. 默认情况下,crosswalk 会生成一个arm和x86 .apk文件 ,我只得到一个。 My apk also was only about 20.3MB , after fixing this it jumped to ~42MB (I think, somewhere around there). 我也APK仅约为20.3MB ,解决这个后跳楼~42MB (我想,在我身边不远)。

After properly including XWalk, HTML5 audio worked and my game ran EXTREMELY more smoothly on Android 4.4. 正确包含XWalk之后,HTML5音频开始工作,并且我的游戏在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 如果仍然无法正常工作(没有手臂和x86 apk,aps仍然很小),请在构建/输出目录中删除旧的apk,然后重新构建

It should be an auto play issue of Chrome WebView, see here Android KitKat (4.4) video autoplay does not work anymore in webview 这应该是Chrome WebView的自动播放问题,请参见此处Android KitKat(4.4)视频自动播放在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. 但是对于Crosswalk,默认情况下已经启用了自动播放功能,只需使用最新的Crosswalk二进制文件仔细检查您的样本,它就可以正常工作。 https://download.01.org/crosswalk/releases/crosswalk/android/canary/8.36.165.0/arm/crosswalk-cordova-8.36.165.0-arm.zip https://download.01.org/crosswalk/releases/crosswalk/android/canary/8.36.165.0/arm/crosswalk-cordova-8.3​​6.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? 在AndroidManifest.xml中?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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