在Apache科尔多瓦Android原生应用的HTML5音频 [英] html5 audio on apache cordova android native app
问题描述
做音频标签工作在Android原生应用?结果
我一直在寻找了一段时间,但我不能找到一个帖子,告诉我,如果它支持与否,还是什么做我必须做的,使其工作。
Do audio tag works on an android native app?
I've been searching a while now, but I can't find a post that tells me if it is supported or not, or what do I have to do to make it work.
<audio id="Multimedia1" controls="controls" width="100%" height="30px">
<source src="file:///android_asset/www/Resources/audio.mp3">
Your browser does not support audio.
</audio>
它不会加载音频。
我尝试过不同的路径,如:
It doesn't load the audio. I've tried different paths, such as:
Resources/audio.mp3
www/Resources/audio.mp3
file:///android_asset/www/Resources/audio.mp3
如果我浏览的浏览器(无原生应用)中的index.html,音频播放罚款的相对路径。
If I browse the index.html with the browser (no native app), the audio plays fine with a relative path.
但我就是不能使它与Apache科尔多瓦应用程序的工作吧。
But I just can't make it work it with an apache cordova app.
任何想法?
在此先感谢!
Any ideas? Thanks in advance!
推荐答案
我曾与科尔多瓦2.3.0从HTML5 音频
标签同样的问题。我落得这样做是使用JavaScript只是发挥他们:
I had the same issue with audio
tags from HTML5 in Cordova 2.3.0. What I ended up doing was to just play them using JavaScript:
这里的 audio.js 的我把在 JS 文件夹:
Here's the audio.js I put in the js folder:
function playAudio(src) {
src = '/android_asset/www/' + src;
var media = new Media(src, success, errorThrown);
media.play();
}
function success() {}
function errorThrown(e) {
alert('Error while playing the sound!');
}
然后在你的HTML code你做的:
And then in your HTML code you do:
<script src="js/audio.js"></script>
和播放声音在此添加一个&LT;脚本&GT;
块:
And to play the sound add this in a <script>
block:
playAudio("media/your_sound.wav");
这篇关于在Apache科尔多瓦Android原生应用的HTML5音频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!