loading checker

This commit is contained in:
DIYgod
2018-03-09 01:41:03 +08:00
parent 2ce5681b7e
commit 5e610b15e8
6 changed files with 64 additions and 2 deletions
+2
View File
@@ -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;
+2
View File
@@ -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
View File
@@ -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;