preloading the next song in a playlist a bit before the current one ends

こ雲淡風輕ζ 提交于 2019-12-04 12:40:40

When you start playing a song you could watch the play event of the audio and already start preloading the next song in the queue.

This is the function I use for preloading audio, you can use it any time, not only in the first time the page being loaded:

function preloadAudio (filename) {

    var sound = new Audio();
    sound.preload = 'auto';

    sound.addEventListener('canplaythrough', function () {
        // now the audio is ready to play through
    });

    document.body.appendChild(sound);

    sound.src = filename;
    sound.load();

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!