javascript - android浏览器无法同时播放多个音频文件?
ringa_lee
ringa_lee 2017-04-10 16:07:53
[JavaScript讨论组]

制作一个小游戏,有背景音乐。

在交互时也有音乐。然而交互音乐响起的时候背景音乐就停掉了,有没有解决方案?

测试iphone是没问题的。android上有什么解决方案又不会影响到iphone效果。

ringa_lee
ringa_lee

ringa_lee

全部回复(1)
巴扎黑

有尝试其它浏览器吗?如果不是浏览器的问题,尝试下以下几个类似问题的解决办法:

类似问题1 Current support on Android for playing multiple audio tracks at a time using the html5 audio tag

类似问题2 Play multiple sound at the same time
及其解决办法:

With JavaScript and the HTML5 Audio API you could do something like this:

    var snd1  = new Audio();
    var src1  = document.createElement("source");
    src1.type = "audio/mpeg";
    src1.src  = "audio/Dombra.mp3";
    snd1.appendChild(src1);

    var snd2  = new Audio();
    var src2  = document.createElement("source");
    src2.type = "audio/mpeg";
    src2.src  = "audio/(TESBIHAT).mp3";
    snd2.appendChild(src2);

    snd1.play(); snd2.play(); // Now both will play at the same time

类似问题3 Multiple tracks on mobile devices

You need to consider the difference between WebAudio and HTML5 audio. WebAudio supports multiple tracks quite happily, whereas HTML5 audio is much more limited (and often painful to use!). Some devices will allow playing more than one HTML5 audio sound at once and others don't. On the whole my experience of HTML5 audio is that it is hugely unreliable and inconsistent, laggy, and generally unpredictable. If you want to use multiple tracks you are definitely better off looking at using WebAudio. But bear in mind that not all mobile browsers support it, although most do these days. In particular the Android stock browser does not support WebAudio.

一篇参考文章Fixing HTML5 Audio Problems in iOS and Android Mobile Browsers to Overcome the Limitations

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号