loading checker
This commit is contained in:
@@ -9,6 +9,7 @@ import menu from '../assets/menu.svg';
|
||||
import loopAll from '../assets/loop-all.svg';
|
||||
import loopOne from '../assets/loop-one.svg';
|
||||
import loopNone from '../assets/loop-none.svg';
|
||||
import loading from '../assets/loading.svg';
|
||||
|
||||
const Icons = {
|
||||
play: play,
|
||||
@@ -22,6 +23,7 @@ const Icons = {
|
||||
loopAll: loopAll,
|
||||
loopOne: loopOne,
|
||||
loopNone: loopNone,
|
||||
loading: loading,
|
||||
};
|
||||
|
||||
export default Icons;
|
||||
|
||||
@@ -250,6 +250,7 @@ class APlayer {
|
||||
this.pause();
|
||||
});
|
||||
|
||||
this.timer.enable('loading');
|
||||
this.timer.enable('progress');
|
||||
|
||||
if (this.options.mutex) {
|
||||
@@ -282,6 +283,7 @@ class APlayer {
|
||||
|
||||
this.audio.pause();
|
||||
|
||||
this.timer.disable('loading');
|
||||
this.timer.disable('progress');
|
||||
});
|
||||
}
|
||||
|
||||
+26
-1
@@ -15,7 +15,7 @@ class Timer {
|
||||
}
|
||||
)();
|
||||
|
||||
this.types = ['progress'];
|
||||
this.types = ['loading', 'progress'];
|
||||
|
||||
this.init();
|
||||
}
|
||||
@@ -42,6 +42,31 @@ class Timer {
|
||||
}, 100);
|
||||
}
|
||||
|
||||
initloadingChecker () {
|
||||
let lastPlayPos = 0;
|
||||
let currentPlayPos = 0;
|
||||
let bufferingDetected = false;
|
||||
this.loadingChecker = setInterval(() => {
|
||||
if (this.enableloadingChecker) {
|
||||
// whether the audio is buffering
|
||||
currentPlayPos = this.player.audio.currentTime;
|
||||
if (!bufferingDetected
|
||||
&& currentPlayPos === lastPlayPos
|
||||
&& !this.player.audio.paused) {
|
||||
this.player.container.classList.add('aplayer-loading');
|
||||
bufferingDetected = true;
|
||||
}
|
||||
if (bufferingDetected
|
||||
&& currentPlayPos > lastPlayPos
|
||||
&& !this.player.audio.paused) {
|
||||
this.player.container.classList.remove('aplayer-loading');
|
||||
bufferingDetected = false;
|
||||
}
|
||||
lastPlayPos = currentPlayPos;
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
|
||||
enable (type) {
|
||||
this[`enable${type}Checker`] = true;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user