docs: update 'self-adapting theme according to cover' (#288)
This commit is contained in:
+14
-3
@@ -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
@@ -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
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user