简体   繁体   English

html5音频:单击后在ipad上“立即”播放声音?

[英]html5 audio: play sounds “instantly” on ipad when clicked?

was writing some script similar to piano, thats mean it should play sounds INSTANTLY when u tap/touch/click the button. 正在写一些类似于钢琴的脚本,这意味着当您点击/触摸/单击按钮时,它应该立即播放声音。

But the problem is that, its seems like it takes time ( which relatively alot ) to play each sounds once tap. 但是问题是,一旦轻按一下,播放每种声音似乎要花费一些时间(相对来说很多)。

as it looks more like streaming which takes times to load :/ 因为它看起来更像是流式传输,需要花费很多时间才能加载:/

Is there any other approach I can use to achieve this ? 我还有其他方法可以用来实现这一目标吗?

Thanks :D , (*for reading at least) 谢谢:D,(*至少阅读)

Preloading <audio> and <video> on iOS devices is disabled to save bandwidth. 禁用在iOS设备上预加载<audio><video>以节省带宽。

In Safari on iOS (for all devices, including iPad), where the user may be on a cellular network and be charged per data unit, preload and autoplay are disabled. 在iOS上的Safari(适用于包括iPad在内的所有设备)上的Safari中,用户可能位于蜂窝网络上,并按数据单元收费,因此预加载和自动播放被禁用。 No data is loaded until the user initiates it. 在用户启动数据之前,不会加载任何数据。

Source: Safari Developer Library 资料来源: Safari开发人员资料库

Do this after DOMContentLoaded : DOMContentLoaded之后执行此操作:

yourAudioElement.play();
setTimeout(function(){
 yourAudioElement.pause();
},1);

This will force iOS browser to cache the resources 这将强制iOS浏览器缓存资源

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

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