diff --git a/src/assets/loading.svg b/src/assets/loading.svg new file mode 100644 index 0000000..f861595 --- /dev/null +++ b/src/assets/loading.svg @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/src/css/index.scss b/src/css/index.scss index c729201..5591655 100644 --- a/src/css/index.scss +++ b/src/css/index.scss @@ -86,6 +86,16 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6; } } + &.aplayer-loading { + .aplayer-info .aplayer-controller .aplayer-loading-icon { + display: block; + } + + .aplayer-info .aplayer-controller .aplayer-bar-wrap .aplayer-bar .aplayer-played .aplayer-thumb { + transform: scale(1); + } + } + .aplayer-icon { width: 15px; height: 15px; @@ -345,6 +355,15 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6; } } } + + .aplayer-loading-icon { + display: none; + + svg { + position: absolute; + animation: rotate 1s linear infinite; + } + } } } @@ -496,3 +515,12 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6; 0%{left:0} 100%{left: -100%} } + +@keyframes rotate { + 0% { + transform: rotate(0) + } + 100% { + transform: rotate(360deg) + } +} \ No newline at end of file diff --git a/src/js/icons.js b/src/js/icons.js index 32fb03f..2f6cdde 100644 --- a/src/js/icons.js +++ b/src/js/icons.js @@ -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; diff --git a/src/js/player.js b/src/js/player.js index 5b6c3a2..6f3b0a9 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -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'); }); } diff --git a/src/js/timer.js b/src/js/timer.js index c0d7593..b1cc569 100644 --- a/src/js/timer.js +++ b/src/js/timer.js @@ -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; diff --git a/src/template/player.art b/src/template/player.art index ef161ff..fd3fa63 100644 --- a/src/template/player.art +++ b/src/template/player.art @@ -14,7 +14,9 @@