Skip to content

Commit

Permalink
fix lrc in fixed mode
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Mar 22, 2018
1 parent 4552dd0 commit 5bfde99
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 18 deletions.
23 changes: 11 additions & 12 deletions demo/demo.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ const setTheme = (index) => {
}
};
setTheme(ap5.list.index);
ap5.on('listswitch', (index) => {
setTheme(index);
ap5.on('listswitch', (data) => {
setTheme(data.index);
});

const ap6 = new APlayer({
Expand Down Expand Up @@ -188,18 +188,17 @@ const ap7 = new APlayer({
}
});

let ap8;
const ap8 = new APlayer({
element: document.getElementById('player8'),
mutex: true,
theme: '#ad7a86',
order: 'random',
lrcType: 3,
fixed: true,
});
$.ajax({
url: 'https://api.i-meto.com/meting/api?server=netease&type=playlist&id=35798529',
success: function (list) {
ap8 = new APlayer({
element: document.getElementById('player8'),
mutex: true,
theme: '#ad7a86',
order: 'random',
lrcType: 3,
fixed: true,
audio: JSON.parse(list)
});
ap8.list.add(JSON.parse(list));
}
});
4 changes: 3 additions & 1 deletion src/css/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ $aplayer-height-lrc: $aplayer-height + $lrc-height - 6;
box-shadow: none;

.aplayer-list {
margin-bottom: 66px;
margin-bottom: 65px;
border: 1px solid #eee;
border-bottom: none;
}

.aplayer-body {
Expand Down
14 changes: 14 additions & 0 deletions src/js/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ class List {
this.player.events.trigger('listadd', {
audios: audios,
});

if (Object.prototype.toString.call(audios) !== '[object Array]') {
audios = [audios];
}
audios.map((item) => {
item.name = item.name || item.title || 'Audio name';
item.artist = item.artist || item.author || 'Audio artist';
item.cover = item.cover || item.pic;
item.type = item.type || 'normal';
return item;
});

const wasSingle = !(this.audios.length > 1);
const wasEmpty = this.audios.length === 0;

Expand Down Expand Up @@ -95,6 +107,7 @@ class List {
list[index].remove();

this.audios.splice(index, 1);
this.lrc.parsed.splice(index, 1);

if (index === this.index) {
if (this.audios[index]) {
Expand Down Expand Up @@ -165,6 +178,7 @@ class List {
this.player.container.classList.remove('aplayer-withlist');
this.player.pause();
this.audios = [];
this.lrc.parsed = [];
this.player.audio.src = '';
this.player.template.listOl.innerHTML = '';
this.player.template.pic.style.backgroundImage = '';
Expand Down
7 changes: 3 additions & 4 deletions src/js/lrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ class Lrc {
this.container = options.container;
this.async = options.async;
this.player = options.player;
this.content = options.content;
this.parsed = [];
this.index = 0;
this.current = [];
Expand Down Expand Up @@ -47,8 +46,8 @@ class Lrc {
switch (index) {
if (!this.parsed[index]) {
if (!this.async) {
if (this.content[index]) {
this.parsed[index] = this.parse(this.content[index]);
if (this.player.list.audios[index].lrc) {
this.parsed[index] = this.parse(this.player.list.audios[index].lrc);
}
else {
this.parsed[index] = [['00:00', 'Not available']];
Expand All @@ -73,7 +72,7 @@ class Lrc {
this.current = this.parsed[index];
}
};
const apiurl = this.content[index];
const apiurl = this.player.list.audios[index].lrc;
xhr.open('get', apiurl, true);
xhr.send(null);
}
Expand Down
1 change: 0 additions & 1 deletion src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ class APlayer {
this.lrc = new Lrc({
container: this.template.lrc,
async: this.options.lrcType === 3,
content: this.options.audio.map((item) => item.lrc),
player: this,
});
}
Expand Down

0 comments on commit 5bfde99

Please sign in to comment.