Skip to content

Commit

Permalink
new api: setMode
Browse files Browse the repository at this point in the history
  • Loading branch information
DIYgod committed Mar 13, 2018
1 parent 738613f commit 1dc058c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
6 changes: 5 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions docs/zh-Hans/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 1dc058c

Please sign in to comment.