mirror of
https://github.com/koel/koel
synced 2024-11-24 21:23:06 +00:00
Preload the next song as soon as we can
This commit is contained in:
parent
933059c672
commit
3fc10e3043
1 changed files with 6 additions and 9 deletions
|
@ -51,21 +51,18 @@ export const playback = {
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempt to preload the next song if the current song is about to end.
|
* Attempt to preload the next song.
|
||||||
*/
|
*/
|
||||||
document.querySelector('.plyr').addEventListener('timeupdate', e => {
|
document.querySelector('.plyr').addEventListener('canplaythrough', e => {
|
||||||
if (!this.player.media.duration || this.player.media.currentTime + 10 < this.player.media.duration) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
// The current song has only 10 seconds left to play.
|
|
||||||
const nextSong = queueStore.next
|
const nextSong = queueStore.next
|
||||||
if (!nextSong || nextSong.preloaded) {
|
if (!nextSong || nextSong.preloaded) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
document.createElement('audio').setAttribute('src', songStore.getSourceUrl(nextSong))
|
const audio = document.createElement('audio')
|
||||||
|
audio.setAttribute('src', songStore.getSourceUrl(nextSong))
|
||||||
|
audio.setAttribute('preload', 'auto')
|
||||||
|
audio.load()
|
||||||
nextSong.preloaded = true
|
nextSong.preloaded = true
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue