rename: music -> audio; title -> name; author -> artist; pic -> cover
This commit is contained in:
+32
-32
@@ -6,11 +6,11 @@ const ap1 = new APlayer({
|
||||
mutex: true,
|
||||
theme: '#e6d0b2',
|
||||
preload: 'metadata',
|
||||
music: {
|
||||
title: 'Preparation',
|
||||
author: 'Hans Zimmer/Richard Harvey',
|
||||
audio: {
|
||||
name: 'Preparation',
|
||||
artist: 'Hans Zimmer/Richard Harvey',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/preparation.mp3',
|
||||
pic: 'https://moeplayer.b0.upaiyun.com/aplayer/preparation.jpg'
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/preparation.jpg'
|
||||
}
|
||||
});
|
||||
ap1.on('play', function () {
|
||||
@@ -42,11 +42,11 @@ const ap2 = new APlayer({
|
||||
lrc: false,
|
||||
mutex: true,
|
||||
theme: '#e6d0b2',
|
||||
music: {
|
||||
title: 'Preparation',
|
||||
author: 'Hans Zimmer/Richard Harvey',
|
||||
audio: {
|
||||
name: 'Preparation',
|
||||
artist: 'Hans Zimmer/Richard Harvey',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/preparation.mp3',
|
||||
pic: 'https://moeplayer.b0.upaiyun.com/aplayer/preparation.jpg'
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/preparation.jpg'
|
||||
}
|
||||
});
|
||||
|
||||
@@ -57,11 +57,11 @@ const ap3 = new APlayer({
|
||||
lrc: 3,
|
||||
mutex: true,
|
||||
theme: '#615754',
|
||||
music: {
|
||||
title: '回レ!雪月花',
|
||||
author: '小倉唯',
|
||||
audio: {
|
||||
name: '回レ!雪月花',
|
||||
artist: '小倉唯',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/snowmoonflowers.mp3',
|
||||
pic: 'https://moeplayer.b0.upaiyun.com/aplayer/snowmoonflowers.jpg',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/snowmoonflowers.jpg',
|
||||
lrc: "https://moeplayer.b0.upaiyun.com/aplayer/snowmoonflowers.lrc"
|
||||
}
|
||||
});
|
||||
@@ -74,24 +74,24 @@ const ap4 = new APlayer({
|
||||
mutex: true,
|
||||
theme: '#ad7a86',
|
||||
order: 'random',
|
||||
music: [
|
||||
audio: [
|
||||
{
|
||||
title: 'あっちゅ~ま青春!',
|
||||
author: '七森中☆ごらく部',
|
||||
name: 'あっちゅ~ま青春!',
|
||||
artist: '七森中☆ごらく部',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/yuruyuri.mp3',
|
||||
pic: 'https://moeplayer.b0.upaiyun.com/aplayer/yuruyuri.jpg'
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/yuruyuri.jpg'
|
||||
},
|
||||
{
|
||||
title: 'secret base~君がくれたもの~',
|
||||
author: '茅野愛衣',
|
||||
name: 'secret base~君がくれたもの~',
|
||||
artist: '茅野愛衣',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/secretbase.mp3',
|
||||
pic: 'https://moeplayer.b0.upaiyun.com/aplayer/secretbase.jpg'
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/secretbase.jpg'
|
||||
},
|
||||
{
|
||||
title: '回レ!雪月花',
|
||||
author: '小倉唯',
|
||||
name: '回レ!雪月花',
|
||||
artist: '小倉唯',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/snowmoonflowers.mp3',
|
||||
pic: 'https://moeplayer.b0.upaiyun.com/aplayer/snowmoonflowers.jpg'
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/snowmoonflowers.jpg'
|
||||
}
|
||||
]
|
||||
});
|
||||
@@ -104,26 +104,26 @@ const ap5 = new APlayer({
|
||||
mutex: true,
|
||||
theme: '#ad7a86',
|
||||
listFolded: true,
|
||||
music: [
|
||||
audio: [
|
||||
{
|
||||
title: 'あっちゅ~ま青春!',
|
||||
author: '七森中☆ごらく部',
|
||||
name: 'あっちゅ~ま青春!',
|
||||
artist: '七森中☆ごらく部',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/yuruyuri.mp3',
|
||||
pic: 'https://moeplayer.b0.upaiyun.com/aplayer/yuruyuri.jpg',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/yuruyuri.jpg',
|
||||
lrc: 'https://moeplayer.b0.upaiyun.com/aplayer/yuruyuri.lrc'
|
||||
},
|
||||
{
|
||||
title: 'secret base~君がくれたもの~',
|
||||
author: '茅野愛衣',
|
||||
name: 'secret base~君がくれたもの~',
|
||||
artist: '茅野愛衣',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/secretbase.mp3',
|
||||
pic: 'https://moeplayer.b0.upaiyun.com/aplayer/secretbase.jpg',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/secretbase.jpg',
|
||||
lrc: 'https://moeplayer.b0.upaiyun.com/aplayer/secretbase.lrc'
|
||||
},
|
||||
{
|
||||
title: '回レ!雪月花',
|
||||
author: '小倉唯',
|
||||
name: '回レ!雪月花',
|
||||
artist: '小倉唯',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/snowmoonflowers.mp3',
|
||||
pic: 'https://moeplayer.b0.upaiyun.com/aplayer/snowmoonflowers.jpg',
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/snowmoonflowers.jpg',
|
||||
lrc: 'https://moeplayer.b0.upaiyun.com/aplayer/snowmoonflowers.lrc'
|
||||
}
|
||||
]
|
||||
|
||||
+9
-9
@@ -61,22 +61,22 @@
|
||||
<button onclick="ap1.volume(0.1)">ap.volume(0.1)</button>
|
||||
<button onclick="ap1.addAudio([
|
||||
{
|
||||
title: 'あっちゅ~ま青春!',
|
||||
author: '七森中☆ごらく部',
|
||||
name: 'あっちゅ~ま青春!',
|
||||
artist: '七森中☆ごらく部',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/yuruyuri.mp3',
|
||||
pic: 'https://moeplayer.b0.upaiyun.com/aplayer/yuruyuri.jpg'
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/yuruyuri.jpg'
|
||||
},
|
||||
{
|
||||
title: 'secret base~君がくれたもの~',
|
||||
author: '茅野愛衣',
|
||||
name: 'secret base~君がくれたもの~',
|
||||
artist: '茅野愛衣',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/secretbase.mp3',
|
||||
pic: 'https://moeplayer.b0.upaiyun.com/aplayer/secretbase.jpg'
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/secretbase.jpg'
|
||||
},
|
||||
{
|
||||
title: '回レ!雪月花',
|
||||
author: '小倉唯',
|
||||
name: '回レ!雪月花',
|
||||
artist: '小倉唯',
|
||||
url: 'https://moeplayer.b0.upaiyun.com/aplayer/snowmoonflowers.mp3',
|
||||
pic: 'https://moeplayer.b0.upaiyun.com/aplayer/snowmoonflowers.jpg'
|
||||
cover: 'https://moeplayer.b0.upaiyun.com/aplayer/snowmoonflowers.jpg'
|
||||
}
|
||||
])">ap.addAudio(...)</button>
|
||||
<button onclick="ap1.destroy()">ap.destroy()</button>
|
||||
|
||||
@@ -51,6 +51,7 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
|
||||
}
|
||||
|
||||
.aplayer {
|
||||
background: #fff;
|
||||
font-family: Arial, Helvetica, sans-serif;
|
||||
margin: 5px;
|
||||
box-shadow: 0 2px 2px 0 rgba(0, 0, 0, 0.07), 0 1px 5px 0 rgba(0, 0, 0, 0.1);
|
||||
|
||||
@@ -33,9 +33,9 @@ class Controller {
|
||||
else {
|
||||
target = e.target.parentElement;
|
||||
}
|
||||
const musicIndex = parseInt(target.getElementsByClassName('aplayer-list-index')[0].innerHTML) - 1;
|
||||
if (musicIndex !== this.player.playIndex) {
|
||||
this.player.switchAudio(musicIndex);
|
||||
const audioIndex = parseInt(target.getElementsByClassName('aplayer-list-index')[0].innerHTML) - 1;
|
||||
if (audioIndex !== this.player.playIndex) {
|
||||
this.player.switchAudio(audioIndex);
|
||||
this.player.play();
|
||||
}
|
||||
else {
|
||||
@@ -153,7 +153,7 @@ class Controller {
|
||||
}
|
||||
|
||||
initMenuButton () {
|
||||
this.player.template.list.style.height = 33 * this.player.options.music.length - 1 + 'px';
|
||||
this.player.template.list.style.height = 33 * this.player.options.audio.length - 1 + 'px';
|
||||
this.player.template.menu.addEventListener('click', () => {
|
||||
if (!this.player.template.list.classList.contains('aplayer-list-hide')) {
|
||||
this.player.template.list.classList.add('aplayer-list-hide');
|
||||
|
||||
+3
-3
@@ -17,11 +17,11 @@ export default (options) => {
|
||||
}
|
||||
}
|
||||
|
||||
if (Object.prototype.toString.call(options.music) !== '[object Array]') {
|
||||
options.music = [options.music];
|
||||
if (Object.prototype.toString.call(options.audio) !== '[object Array]') {
|
||||
options.audio = [options.audio];
|
||||
}
|
||||
|
||||
if (options.music.length <= 1 && options.loop === 'one') {
|
||||
if (options.audio.length <= 1 && options.loop === 'one') {
|
||||
options.loop = 'all';
|
||||
}
|
||||
|
||||
|
||||
+27
-36
@@ -28,13 +28,13 @@ class APlayer {
|
||||
this.paused = true;
|
||||
this.playedPromise = Promise.resolve();
|
||||
|
||||
this.randomOrder = utils.randomOrder(this.options.music.length);
|
||||
this.randomOrder = utils.randomOrder(this.options.audio.length);
|
||||
|
||||
this.container.classList.add('aplayer');
|
||||
if (this.options.lrc) {
|
||||
this.container.classList.add('aplayer-withlrc');
|
||||
}
|
||||
if (this.options.music.length > 1) {
|
||||
if (this.options.audio.length > 1) {
|
||||
this.container.classList.add('aplayer-withlist');
|
||||
}
|
||||
if (utils.isMobile) {
|
||||
@@ -53,8 +53,8 @@ class APlayer {
|
||||
if (this.options.lrc === 2 || this.options.lrc === true) {
|
||||
const lrcEle = this.container.getElementsByClassName('aplayer-lrc-content');
|
||||
for (let i = 0; i < lrcEle.length; i++) {
|
||||
if (this.options.music[i]) {
|
||||
this.options.music[i].lrc = lrcEle[i].innerHTML;
|
||||
if (this.options.audio[i]) {
|
||||
this.options.audio[i].lrc = lrcEle[i].innerHTML;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,7 +73,7 @@ class APlayer {
|
||||
this.lrc = new Lrc({
|
||||
container: this.template.lrc,
|
||||
async: this.options.lrc === 3,
|
||||
content: this.options.music.map((item) => item.lrc),
|
||||
content: this.options.audio.map((item) => item.lrc),
|
||||
player: this,
|
||||
});
|
||||
}
|
||||
@@ -139,16 +139,16 @@ class APlayer {
|
||||
this.template.author.innerHTML = ` - Error happens ╥﹏╥`;
|
||||
});
|
||||
|
||||
// multiple music play
|
||||
// multiple audio play
|
||||
this.on('ended', () => {
|
||||
if (this.options.loop === 'none') {
|
||||
if (this.options.order === 'list') {
|
||||
if (this.playIndex < this.options.music.length - 1) {
|
||||
this.switchAudio((this.playIndex + 1) % this.options.music.length);
|
||||
if (this.playIndex < this.options.audio.length - 1) {
|
||||
this.switchAudio((this.playIndex + 1) % this.options.audio.length);
|
||||
this.play();
|
||||
}
|
||||
else {
|
||||
this.switchAudio((this.playIndex + 1) % this.options.music.length);
|
||||
this.switchAudio((this.playIndex + 1) % this.options.audio.length);
|
||||
this.pause();
|
||||
}
|
||||
}
|
||||
@@ -169,7 +169,7 @@ class APlayer {
|
||||
}
|
||||
else if (this.options.loop === 'all') {
|
||||
if (this.options.order === 'list') {
|
||||
this.switchAudio((this.playIndex + 1) % this.options.music.length);
|
||||
this.switchAudio((this.playIndex + 1) % this.options.audio.length);
|
||||
}
|
||||
else if (this.options.order === 'random') {
|
||||
this.switchAudio(this.nextRandomNum());
|
||||
@@ -181,9 +181,6 @@ class APlayer {
|
||||
this.volume(this.user.get('volume'), true, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set music
|
||||
*/
|
||||
switchAudio (index) {
|
||||
this.handlePlayPromise(() => {
|
||||
if (typeof index !== 'undefined') {
|
||||
@@ -191,14 +188,14 @@ class APlayer {
|
||||
}
|
||||
|
||||
// set html
|
||||
if (this.options.music[this.playIndex].pic) {
|
||||
this.template.pic.style.backgroundImage = `url('${this.options.music[this.playIndex].pic}')`;
|
||||
if (this.options.audio[this.playIndex].cover) {
|
||||
this.template.pic.style.backgroundImage = `url('${this.options.audio[this.playIndex].cover}')`;
|
||||
}
|
||||
else {
|
||||
this.template.pic.style.backgroundImage = '';
|
||||
}
|
||||
this.template.title.innerHTML = this.options.music[this.playIndex].title;
|
||||
this.template.author.innerHTML = this.options.music[this.playIndex].author ? ' - ' + this.options.music[this.playIndex].author : '';
|
||||
this.template.title.innerHTML = this.options.audio[this.playIndex].name;
|
||||
this.template.author.innerHTML = this.options.audio[this.playIndex].artist ? ' - ' + this.options.audio[this.playIndex].artist : '';
|
||||
const light = this.container.getElementsByClassName('aplayer-list-light')[0];
|
||||
if (light) {
|
||||
light.classList.remove('aplayer-list-light');
|
||||
@@ -207,7 +204,7 @@ class APlayer {
|
||||
|
||||
this.template.list.scrollTop = this.playIndex * 33;
|
||||
|
||||
this.audio.src = this.options.music[this.playIndex].url;
|
||||
this.audio.src = this.options.audio[this.playIndex].url;
|
||||
this.seek(0);
|
||||
|
||||
let playPromise;
|
||||
@@ -246,9 +243,6 @@ class APlayer {
|
||||
this.template.ptime.innerHTML = utils.secondToTime(time);
|
||||
}
|
||||
|
||||
/**
|
||||
* Play music
|
||||
*/
|
||||
play () {
|
||||
this.handlePlayPromise(() => {
|
||||
if (this.paused) {
|
||||
@@ -281,9 +275,6 @@ class APlayer {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Pause music
|
||||
*/
|
||||
pause () {
|
||||
this.handlePlayPromise(() => {
|
||||
if (!this.paused) {
|
||||
@@ -360,10 +351,10 @@ class APlayer {
|
||||
}
|
||||
|
||||
/**
|
||||
* get whether multiple music definitions are loaded
|
||||
* get whether multiple audio definitions are loaded
|
||||
*/
|
||||
isMultiple () {
|
||||
return this.options.music.length > 1;
|
||||
return this.options.audio.length > 1;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -385,23 +376,23 @@ class APlayer {
|
||||
}
|
||||
|
||||
/**
|
||||
* add music dynamically
|
||||
* add audio dynamically
|
||||
*
|
||||
* @param {Array} newMusic
|
||||
*/
|
||||
addAudio (newMusic) {
|
||||
const wasSingle = !this.isMultiple();
|
||||
|
||||
this.options.music = this.options.music.concat(newMusic);
|
||||
this.options.audio = this.options.audio.concat(newMusic);
|
||||
|
||||
let newItemHTML = ``;
|
||||
for (let i = 0; i < newMusic.length; i++) {
|
||||
newItemHTML += `
|
||||
<li>
|
||||
<span class="aplayer-list-cur" style="background: ${this.options.theme};"></span>
|
||||
<span class="aplayer-list-index">${this.options.music.length - newMusic.length + i + 1}</span>
|
||||
<span class="aplayer-list-title">${newMusic[i].title}</span>
|
||||
<span class="aplayer-list-author">${newMusic[i].author}</span>
|
||||
<span class="aplayer-list-index">${this.options.audio.length - newMusic.length + i + 1}</span>
|
||||
<span class="aplayer-list-title">${newMusic[i].name}</span>
|
||||
<span class="aplayer-list-author">${newMusic[i].artist}</span>
|
||||
</li>`;
|
||||
}
|
||||
this.template.listOl.innerHTML += newItemHTML;
|
||||
@@ -413,20 +404,20 @@ class APlayer {
|
||||
const songListLength = this.container.querySelectorAll('.aplayer-list li').length;
|
||||
this.template.list.style.height = songListLength * 33 - 1 + 'px';
|
||||
|
||||
this.randomOrder = utils.randomOrder(this.options.music.length);
|
||||
this.randomOrder = utils.randomOrder(this.options.audio.length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove song from playlist
|
||||
*/
|
||||
removeAudio (index) {
|
||||
if (this.options.music[index] && this.options.music.length > 1) {
|
||||
if (this.options.audio[index] && this.options.audio.length > 1) {
|
||||
const list = this.container.querySelectorAll('.aplayer-list li');
|
||||
|
||||
this.options.music.splice(index, 1);
|
||||
this.options.audio.splice(index, 1);
|
||||
|
||||
if (index === this.playIndex) {
|
||||
if (this.options.music[index + 1]) {
|
||||
if (this.options.audio[index + 1]) {
|
||||
this.switchAudio(index);
|
||||
}
|
||||
else {
|
||||
@@ -441,7 +432,7 @@ class APlayer {
|
||||
for (let i = index; i < list.length; i++) {
|
||||
list[i].getElementsByClassName('aplayer-list-index')[0].textContent = i;
|
||||
}
|
||||
if (this.options.music.length === 1) {
|
||||
if (this.options.audio.length === 1) {
|
||||
this.container.classList.remove('aplayer-withlist');
|
||||
}
|
||||
this.template.list.style.height = parseInt(this.template.list.style.height, 10) - 33 + 'px';
|
||||
|
||||
+4
-4
@@ -10,18 +10,18 @@ class Template {
|
||||
}
|
||||
|
||||
init () {
|
||||
let pic;
|
||||
let cover;
|
||||
if (this.options.order === 'random') {
|
||||
pic = this.options.music[this.randomOrder[0]].pic;
|
||||
cover = this.options.audio[this.randomOrder[0]].cover;
|
||||
}
|
||||
else {
|
||||
pic = this.options.music[0].pic;
|
||||
cover = this.options.audio[0].cover;
|
||||
}
|
||||
|
||||
this.container.innerHTML = tplPlayer({
|
||||
options: this.options,
|
||||
icons: Icons,
|
||||
pic: pic,
|
||||
cover: cover,
|
||||
});
|
||||
|
||||
this.lrc = this.container.querySelector('.aplayer-lrc-contents');
|
||||
|
||||
+1
-1
@@ -70,7 +70,7 @@ const utils = {
|
||||
/**
|
||||
* get random order, using Fisher–Yates shuffle
|
||||
*/
|
||||
randomOrder: (length = this.options.music.length) => {
|
||||
randomOrder: (length = this.options.audio.length) => {
|
||||
function shuffle (arr) {
|
||||
for (let i = arr.length - 1; i >= 0; i--) {
|
||||
const randomIndex = Math.floor(Math.random() * (i + 1));
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<div class="aplayer-pic"{{ if pic }} style="background-image: url("{{ pic }}");"{{ /if }}>
|
||||
<div class="aplayer-pic"{{ if cover }} style="background-image: url("{{ cover }}");"{{ /if }}>
|
||||
<div class="aplayer-button aplayer-play">{{@ icons.play }}</div>
|
||||
</div>
|
||||
<div class="aplayer-info">
|
||||
@@ -34,7 +34,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{{ if options.music.length > 1 }}
|
||||
{{ if options.audio.length > 1 }}
|
||||
<button type="button" class="aplayer-icon aplayer-icon-order">
|
||||
{{ if options.order === 'list' }}{{@ icons.orderList }}{{ else if options.order === 'random' }}{{@ icons.orderRandom }}{{ /if }}
|
||||
</button>
|
||||
@@ -50,12 +50,12 @@
|
||||
</div>
|
||||
<div class="aplayer-list{{ if options.listFolded }} aplayer-list-hide{{ /if }}"{{ if options.listMaxHeight }} style="max-height: {{ options.listMaxHeight }}"{{ /if }}>
|
||||
<ol>
|
||||
{{each options.music}}
|
||||
{{each options.audio}}
|
||||
<li>
|
||||
<span class="aplayer-list-cur" style="background: {{ options.theme }};"></span>
|
||||
<span class="aplayer-list-index">{{ $index + 1 }}</span>
|
||||
<span class="aplayer-list-title">{{ $value.title }}</span>
|
||||
<span class="aplayer-list-author">{{ $value.author }}</span>
|
||||
<span class="aplayer-list-title">{{ $value.name }}</span>
|
||||
<span class="aplayer-list-author">{{ $value.artist }}</span>
|
||||
</li>
|
||||
{{/each}}
|
||||
</ol>
|
||||
|
||||
Reference in New Issue
Block a user