@@ -178,6 +178,12 @@ const ap = new APlayer({
178178 ap .volume (0.1 , true );
179179 ```
180180
181+ + ` ap.theme(color: string, index: number) ` : set player theme, the default of index is current audio index.
182+
183+ ``` js
184+ ap .theme (' #000' , 0 );
185+ ```
186+
181187+ ` ap.destroy() ` : destroy player
182188
183189+ ` ap.audio ` : native audio
@@ -393,6 +399,48 @@ const ap = new APlayer({
393399});
394400```
395401
402+ ## Self-adapting theme according to cover
403+
404+ It requires the library [ color-thief] ( https://github.com/lokesh/color-thief/blob/master/src/color-thief.js ) .
405+
406+ <div class =" aplayer-wrap " >
407+ <div id="aplayer7"><button class="docute-button load">Click to load player</div>
408+ </div >
409+
410+ ``` html
411+ <link rel =" stylesheet" href =" APlayer.min.css" >
412+ <div id =" aplayer" ></div >
413+ <script src =" APlayer.min.js" ></script >
414+ <script src =" color-thief.js" ></script >
415+ ```
416+
417+ ``` js
418+ const ap = new APlayer ({
419+ container: document .getElementById (' aplayer' ),
420+ theme: ' #e9e9e9' ,
421+ audio: [{
422+ name: ' name1' ,
423+ artist: ' artist1' ,
424+ url: ' url1.mp3' ,
425+ cover: ' cover1.jpg'
426+ }, {
427+ name: ' name2' ,
428+ artist: ' artist2' ,
429+ url: ' url2.mp3' ,
430+ cover: ' cover2.jpg'
431+ }]
432+ });
433+
434+ const colorThief = new ColorThief ();
435+ ap .on (' switchaudio' , (index ) => {
436+ if (! ap .options .audio [index].theme ) {
437+ colorThief .getColorAsync (ap .options .audio [index].cover , (color ) => {
438+ ap .theme (` rgb(${ color[0 ]} , ${ color[1 ]} , ${ color[2 ]} )` , index);
439+ });
440+ }
441+ });
442+ ```
443+
396444## CDN
397445
398446- [ jsDelivr] ( https://www.jsdelivr.com/package/npm/aplayer )
0 commit comments