docs: update 'self-adapting theme according to cover' (#288)

This commit is contained in:
Soptq
2020-05-23 11:32:25 +08:00
committed by GitHub
parent 1efe60189c
commit 44c6552332
3 changed files with 44 additions and 11 deletions
+14 -3
View File
@@ -136,11 +136,22 @@ const ap5 = new APlayer({
}]
});
const colorThief = new ColorThief();
const image = new Image();
const xhr = new XMLHttpRequest();
const setTheme = (index) => {
if (!ap5.list.audios[index].theme) {
colorThief.getColorAsync(ap5.list.audios[index].cover, function (color) {
ap5.theme(`rgb(${color[0]}, ${color[1]}, ${color[2]})`, index);
});
xhr.onload = function(){
let coverUrl = URL.createObjectURL(this.response);
image.onload = function(){
let color = colorThief.getColor(image);
ap5.theme(`rgb(${color[0]}, ${color[1]}, ${color[2]})`, index);
URL.revokeObjectURL(coverUrl)
};
image.src = coverUrl;
}
xhr.open('GET', ap5.list.audios[index].cover, true);
xhr.responseType = 'blob';
xhr.send();
}
};
setTheme(ap5.list.index);
+16 -5
View File
@@ -555,16 +555,27 @@ const ap = new APlayer({
});
const colorThief = new ColorThief();
const image = new Image();
const xhr = new XMLHttpRequest();
const setTheme = (index) => {
if (!ap.list.audios[index].theme) {
colorThief.getColorAsync(ap.list.audios[index].cover, function (color) {
ap.theme(`rgb(${color[0]}, ${color[1]}, ${color[2]})`, index);
});
xhr.onload = function(){
let coverUrl = URL.createObjectURL(this.response);
image.onload = function(){
let color = colorThief.getColor(image);
ap.theme(`rgb(${color[0]}, ${color[1]}, ${color[2]})`, index);
URL.revokeObjectURL(coverUrl)
};
image.src = coverUrl;
}
xhr.open('GET', ap.list.audios[index].cover, true);
xhr.responseType = 'blob';
xhr.send();
}
};
setTheme(ap.list.index);
ap.on('listswitch', (data) => {
setTheme(data.index);
ap.on('listswitch', (index) => {
setTheme(index);
});
```
+14 -3
View File
@@ -555,11 +555,22 @@ const ap = new APlayer({
});
const colorThief = new ColorThief();
const image = new Image();
const xhr = new XMLHttpRequest();
const setTheme = (index) => {
if (!ap.list.audios[index].theme) {
colorThief.getColorAsync(ap.list.audios[index].cover, function (color) {
ap.theme(`rgb(${color[0]}, ${color[1]}, ${color[2]})`, index);
});
xhr.onload = function(){
let coverUrl = URL.createObjectURL(this.response);
image.onload = function(){
let color = colorThief.getColor(image);
ap.theme(`rgb(${color[0]}, ${color[1]}, ${color[2]})`, index);
URL.revokeObjectURL(coverUrl)
};
image.src = coverUrl;
}
xhr.open('GET', ap.list.audios[index].cover, true);
xhr.responseType = 'blob';
xhr.send();
}
};
setTheme(ap.list.index);