大佬教程收集整理的这篇文章主要介绍了html5 – 预加载多个音频文件,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我正在做的一个粗略的想法:
http://jsfiddle.net/L0c9ccx9/20/
audio.src = ...; audio.load(); audio.play();
var audioFiles = [ "http://www.teanglAnn.ie/CanC/nua.mp3","http://www.teanglAnn.ie/CanC/ag.mp3","http://www.teanglAnn.ie/CanC/dul.mp3","http://www.teanglAnn.ie/CanC/freisin.mp3" ]; function preloadAudio(url) { var audio = new Audio(); // once this file loads,it will call loadedAudio() // the file will be kept by the browser as cache audio.addEventListener('canplaythrough',loadedAudio,falsE); audio.src = url; } var loaded = 0; function loadedAudio() { // this will be called every time an audio file is loaded // we keep track of the loaded files vs the requested files loaded++; if (loaded == audioFiles.length){ // all have loaded init(); } } var player = document.getElementById('player'); function play(indeX) { player.src = audioFiles[index]; player.play(); } function init() { // do your stuff here,audio has been loaded // for example,play all files one after the other var i = 0; // once the player ends,play the next one player.onended = function() { i++; if (i >= audioFiles.length) { // end return; } play(i); }; // play the first file play(i); } // we start preloading all the audio files for (var i in audioFiles) { preloadAudio(audioFiles[i]); }
<audio id="player"></audio>
以上是大佬教程为你收集整理的html5 – 预加载多个音频文件全部内容,希望文章能够帮你解决html5 – 预加载多个音频文件所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。