我需要一些帮助。
我正在用HTML5构建一个应用程序,并使用“Intel XDK”将其转换为适用于安卓系统的.apk。我唯一的问题是“循环”音频文件。我使用了一个非常简单的代码:
<audio id="myAudio" autoplay loop>
<source src="sounds/mysound.mp3" type="audio/mpeg"/>
<source src="sounds/mysound.ogg" type="audio/ogg"/>
</audio>当我测试应用程序时,声音会播放,但只播放一次,没有循环。
提前感谢!
发布于 2014-10-22 05:31:42
您可以通过以下方式在HTML中的Java script中实现这一点:
<script language="JavaScript" type="text/javascript">
var mp3snd = "songlocation.mp3";
var oggsnd = "home-sound.ogg";
document.write('<audio loop autoplay="autoplay">');
document.write('<source src="'+mp3snd+'" type="audio/mpeg">');
document.write('<source src="'+oggsnd+'" type="audio/ogg">');
document.write('<!--[if lt IE 9]>');
document.write('<bgsound src="'+mp3snd+'" loop="1">');
document.write('<![endif]-->');
document.write('</audio>');
//-->
</script>它将达到您想要的效果(在后台播放),同时仍然是在HTML5中。
安装this插件可能也会有所帮助。
发布于 2014-10-25 20:56:55
(针对XDK Android Sound Loop问题的更新)
所以我做了一个折衷方案,这个方案是可行的!应用程序运行时会循环,但手机锁定时不会运行。已使用英特尔XDK Android版本进行测试。
我创建了一个内部IFRAME,它会在声音结束时自动刷新。下面是一个1分钟的声音示例:
在需要音频的页面上:
<div id="audio_stream" style="position: absolute; margin-left: -1000px;">
<iframe src="iframes/audiotrack.html"></iframe>
</div>这是IFRAME代码:(位置:iframes/IFRAME otrack.html)
<!--First, include refresh in meta-->
<meta http-equiv="refresh" content="60;url=audiotrack.html" />
<!--now enter audio that you wish to loop-->
<div id="audio_stream">
<audio controls autoplay="autoplay">
<source src="../sounds/FX/audiotrack.mp3" type="audio/mpeg"/>
</audio>
</div>所以它是有效的,但不是在后台。有没有人知道如何在手机锁定的情况下继续播放?
https://stackoverflow.com/questions/26496667
复制相似问题