$ P $当前的结束前ploading下一首播放列表中的一个位 [英] preloading the next song in a playlist a bit before the current one ends

查看:142
本文介绍了$ P $当前的结束前ploading下一首播放列表中的一个位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个小的媒体播放器,工作正常,但我希望让这个没有更多的装载在每个歌曲之间

I've made a small media player that works fine but I want to make it so that there's no more loading in between each songs

我知道了preLOAD属性,但它只是preloads在页面加载时的第一次,所以我觉得这不会工作的音乐

I know about the preload property but it only preloads the music when the page loads for the first time, so I feel like this wont work

有没有办法做到这一点呢?也许使用网络音频API?

is there a way to do this at all? maybe using the web audio API?

推荐答案

当你开始播放歌曲,你可以看播放音频的事件,并已开始preloading下一首歌曲在队列中。

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.

这是我使用preloading音频的功能,你可以使用它的任何时间,不仅在第一时间被加载的页面:

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();

}

这篇关于$ P $当前的结束前ploading下一首播放列表中的一个位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆