new api: setMode

This commit is contained in:
DIYgod
2018-03-13 17:37:48 +08:00
parent 738613fffe
commit 1dc058c0c7
3 changed files with 27 additions and 2 deletions
+5 -1
View File
@@ -178,12 +178,16 @@ const ap = new APlayer({
ap.volume(0.1, true);
```
+ `ap.theme(color: string, index: number)`: set player theme, the default of index is current audio index.
+ `ap.theme(color: string, index: number)`: set player theme, the default of index is current audio index
```js
ap.theme('#000', 0);
```
+ `ap.setMode(mode: string)`: set player mode, the value of mode should be 'mini' or 'normal'
+ `ap.mode`: return current player mode, 'mini' or 'normal'
+ `ap.destroy()`: destroy player
+ `ap.audio`: native audio
+10
View File
@@ -179,6 +179,16 @@ const ap = new APlayer({
ap.volume(0.1, true);
```
+ `ap.theme(color: string, index: number)`: 设置播放器主题色, index 默认为当前音频的 index
```js
ap.theme('#000', 0);
```
+ `ap.setMode(mode: string)`: 设置播放器模式,mode 取值应为 'mini' 或 'normal'
+ `ap.mode`: 返回播放器当前模式,'mini' 或 'normal'
+ `ap.destroy()`: 销毁播放器
+ `ap.audio`: 原生 video
+12 -1
View File
@@ -27,6 +27,7 @@ class APlayer {
this.playIndex = 0;
this.paused = true;
this.playedPromise = Promise.resolve();
this.mode = 'normal';
this.randomOrder = utils.randomOrder(this.options.audio.length);
@@ -45,7 +46,7 @@ class APlayer {
this.container.classList.add('aplayer-arrow');
}
if (this.options.mini) {
this.container.classList.add('aplayer-narrow');
this.setMode('mini');
}
// save lrc
@@ -477,6 +478,16 @@ class APlayer {
this.events.trigger('destroy');
}
setMode (mode = 'normal') {
this.mode = mode;
if (mode === 'mini') {
this.container.classList.add('aplayer-narrow');
}
else if (mode === 'normal') {
this.container.classList.remove('aplayer-narrow');
}
}
handlePlayPromise (callback) {
this.playedPromise = this.playedPromise.then(callback).catch((err) => {
console.error(err);