setAudio -> switchAudio
This commit is contained in:
@@ -73,6 +73,7 @@ const ap4 = new APlayer({
|
||||
lrc: false,
|
||||
mutex: true,
|
||||
theme: '#ad7a86',
|
||||
order: 'random',
|
||||
music: [
|
||||
{
|
||||
title: 'あっちゅ~ま青春!',
|
||||
|
||||
+1
-1
@@ -83,7 +83,7 @@
|
||||
<h3>With playlist</h3>
|
||||
<div id="player4" class="aplayer"></div>
|
||||
<p></p>
|
||||
<button onclick="ap4.setAudio(2)">ap.setAudio(2)</button>
|
||||
<button onclick="ap4.switchAudio(2)">ap.switchAudio(2)</button>
|
||||
<h3>With lyrics</h3>
|
||||
<div id="player3" class="aplayer"></div>
|
||||
<h3>With playlist and lyrics</h3>
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+13
-13
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user