From ddc529397dc0900f41dbf78301527c9ab250ca31 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Fri, 9 Mar 2018 14:39:17 +0800 Subject: [PATCH] setAudio -> switchAudio --- demo/demo.js | 1 + demo/index.html | 2 +- src/js/controller.js | 2 +- src/js/player.js | 26 +++++++++++++------------- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/demo/demo.js b/demo/demo.js index 45666c9..8a04dfe 100644 --- a/demo/demo.js +++ b/demo/demo.js @@ -73,6 +73,7 @@ const ap4 = new APlayer({ lrc: false, mutex: true, theme: '#ad7a86', + order: 'random', music: [ { title: 'あっちゅ~ま青春!', diff --git a/demo/index.html b/demo/index.html index ed11193..d13ce36 100644 --- a/demo/index.html +++ b/demo/index.html @@ -83,7 +83,7 @@

With playlist

- +

With lyrics

With playlist and lyrics

diff --git a/src/js/controller.js b/src/js/controller.js index 294f8bf..74cc415 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -35,7 +35,7 @@ class Controller { } const musicIndex = parseInt(target.getElementsByClassName('aplayer-list-index')[0].innerHTML) - 1; if (musicIndex !== this.player.playIndex) { - this.player.setAudio(musicIndex); + this.player.switchAudio(musicIndex); this.player.play(); } else { diff --git a/src/js/player.js b/src/js/player.js index ea1581b..bac828a 100644 --- a/src/js/player.js +++ b/src/js/player.js @@ -85,10 +85,10 @@ class APlayer { this.initAudio(); if (this.options.order === 'random') { - this.setAudio(this.randomOrder[0]); + this.switchAudio(this.randomOrder[0]); } else { - this.setAudio(0); + this.switchAudio(0); } // autoplay @@ -144,35 +144,35 @@ class APlayer { if (this.options.loop === 'none') { if (this.options.order === 'list') { if (this.playIndex < this.options.music.length - 1) { - this.setAudio((this.playIndex + 1) % this.options.music.length); + this.switchAudio((this.playIndex + 1) % this.options.music.length); this.play(); } else { - this.setAudio((this.playIndex + 1) % this.options.music.length); + this.switchAudio((this.playIndex + 1) % this.options.music.length); this.pause(); } } else if (this.options.order === 'random') { if (this.randomOrder.indexOf(this.playIndex) < this.randomOrder.length - 1) { - this.setAudio(this.nextRandomNum()); + this.switchAudio(this.nextRandomNum()); this.play(); } else { - this.setAudio(this.nextRandomNum()); + this.switchAudio(this.nextRandomNum()); this.pause(); } } } else if (this.options.loop === 'one') { - this.setAudio(this.playIndex); + this.switchAudio(this.playIndex); this.play(); } else if (this.options.loop === 'all') { if (this.options.order === 'list') { - this.setAudio((this.playIndex + 1) % this.options.music.length); + this.switchAudio((this.playIndex + 1) % this.options.music.length); } else if (this.options.order === 'random') { - this.setAudio(this.nextRandomNum()); + this.switchAudio(this.nextRandomNum()); } this.play(); } @@ -184,7 +184,7 @@ class APlayer { /** * Set music */ - setAudio (index) { + switchAudio (index) { this.handlePlayPromise(() => { if (typeof index !== 'undefined') { this.playIndex = index; @@ -396,7 +396,7 @@ class APlayer { this.audio.loop = false; } const songListLength = this.container.querySelectorAll('.aplayer-list li').length; - this.template.list.style.height = songListLength * 33 + 'px'; + this.template.list.style.height = songListLength * 33 - 1 + 'px'; this.randomOrder = utils.randomOrder(this.options.music.length); } @@ -409,10 +409,10 @@ class APlayer { const list = this.container.querySelectorAll('.aplayer-list li'); if (index === this.playIndex) { if (this.options.music[index + 1]) { - this.setAudio(index + 1); + this.switchAudio(index + 1); } else { - this.setAudio(index - 1); + this.switchAudio(index - 1); } } if (this.playIndex > index) {