Skip to content

Commit c665854

Browse files
committed
Merge branch 'release/1.4.0'
2 parents 2dca597 + 9be9217 commit c665854

13 files changed

+619
-392
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- Playlist
1717
- Lyrics scroll
1818
- Custom theme color / Self-adapting theme color
19+
- Drag and place anywhere
1920
- Mutex play
2021
- HLS support
2122

@@ -26,11 +27,10 @@ Using Vue-APlayer in your project? [Let me know!](https://github.com/SevenOutman
2627
```HTML
2728
<aplayer autoplay
2829
:music="{
29-
title: 'Preparation',
30-
author: 'Hans Zimmer/Richard Harvey',
31-
url: 'http://devtest.qiniudn.com/Preparation.mp3',
32-
pic: 'http://devtest.qiniudn.com/Preparation.jpg',
33-
lrc: '[00:00.00]lrc here\n[00:01.00]aplayer'
30+
title: 'secret base~君がくれたもの~',
31+
author: 'Silent Siren',
32+
url: 'https://moeplayer.b0.upaiyun.com/aplayer/secretbase.mp3',
33+
pic: 'https://moeplayer.b0.upaiyun.com/aplayer/secretbase.jpg'
3434
}"
3535
/>
3636
```
@@ -45,6 +45,8 @@ Feel free to [open an issue](https://github.com/SevenOutman/vue-aplayer/issues)
4545
## Thanks
4646
[APlayer](https://github.com/MoePlayer/APlayer), for appearance&api design inspiration and prototyping.
4747

48+
[@DIYgod](https://github.com/DIYgod), for creating APlayer and sharing cloud storage for hosting my demo page media resources.
49+
4850
## License
4951

5052
[MIT Licensed](https://github.com/SevenOutman/vue-aplayer/blob/master/LICENSE). Copyright (c) 2016-present Shenghao "Doma" Lei

docs/README.md

Lines changed: 46 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@
44
$ npm install vue-aplayer --save
55
```
66

7+
8+
79
## Requirements
810

9-
- Promise
10-
- fetch
11+
- [Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)
12+
- [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API)
13+
14+
1115

1216
## Usage
1317

@@ -34,59 +38,73 @@ new Vue({
3438
})
3539
```
3640

37-
### Props
3841

39-
Props are mostly the same as [APlayer's options](https://aplayer.js.org/#/home?id=options).
42+
43+
### Props
4044

4145
| Name | Type | Default | Description |
4246
| ---- | ---- | ------- | ----------- |
4347
| music| Object | *required* | Music info for current playing music, see [Music info](https://github.com/SevenOutman/vue-aplayer#music-info) |
4448
| list | Array | `[]` | Music list to play and display. If list is not empty, music list panel will be shown, even if the only song in the list is identical to music prop. |
4549
| mini | Boolean | `false` | Mini mode |
4650
| float | Boolean | `false` | Float mode, in which you can drag the player around and leave it anywhere on your page |
47-
| autoplay | Boolean | `false` | Whether to autoplay. If more than one mutex player are set autoplay, only the first one will play. |
4851
| showLrc | Boolean | `false` | Whether to show lyrics or not |
4952
| mutex | Boolean | `true` | Pause other players when this player is playing |
50-
| theme | String | `'#b7daff'` | Theme color, will be overridden by current `music`'s theme if set |
53+
| theme | String | `'#41b883'` | Theme color, will be overridden by current `music`'s theme if set |
5154
| mode | String | `'circulation'` | Play mode, can be 'random' 'single 'circulation'(loop) or 'order'(no loop) |
52-
| preload | String | `'auto'` | The way to load music, can be 'none' 'metadata' or 'auto' |
5355
| listMaxHeight | String | *none* | Max height of play list |
5456
| narrow | | | DEPRECATED, use `mini` instead |
5557
| listmaxheight | | | DEPRECATED, use `listMaxHeight` instead |
5658
| showlrc | | | DEPRECATED, use `showLrc` instead |
5759

58-
> If you are using Vue@2.3.0+, you can use [`.sync` Modifier](https://vuejs.org/v2/guide/components.html#sync-Modifier) on `music` and `mode` prop.
60+
> If you are using Vue@2.3.0+, you can use [`.sync` Modifier](https://vuejs.org/v2/guide/components.html#sync-Modifier) on `music` and `mode` props.
61+
62+
63+
64+
### Audio attributes as props
65+
66+
Since `v1.4.0`, we added some props that names after `<audio>` attributes and also work as they do
67+
68+
| Name | Type | Default | Observable | Description |
69+
| ---- | ---- | ------- | ---------- | ---------- |
70+
| autoplay | Boolean | `false` | false | Starts playing as soon as loaded. If more than one mutex player are set autoplay, only the first one will play.|
71+
| controls | Boolean | `false` | true | Shows native audio controls below the player, or between player and playlist. This only works in develop environment, and doesn't work in Mini mode. |
72+
| muted | Boolean | `false` | true | Player is muted. |
73+
| preload | String | *none* | true | The way to load music, can be 'none' 'metadata' or 'auto' |
74+
| volume | Number | `0.8` | true | Playback volume. |
75+
76+
> `muted` and `volume` props also accept `.sync` modifier, allowing you some custom external control capability.
77+
78+
5979

6080
### Music info
6181

62-
The `music` props can either be an object containing info of the song to play, or an array of such objects.
82+
The `music` props contains info of the song to play.
6383

6484
| Property | Default | Description |
6585
| -------- | ------- | ----------- |
66-
| url | *required* | Music source url |
86+
| src | *required* | Music source url |
6787
| title | `'Untitled'` | Music title |
6888
| author | `'Unknown'` | Music author |
6989
| pic | *none* | Music cover picture |
70-
| theme | *none* | Song-specific theme color |
7190
| lrc | *none* | lrc or url to a .lrc file, see: [LRC](https://aplayer.js.org/#/home?id=lrc) |
91+
| theme | *none* | Song-specific theme color |
92+
| url || DEPRECATED, use `src` instead |
93+
7294

73-
> vue-aplayer uses [fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API) to load your lrc when it's a url.
74-
> If your browser doesn't support fetch by default, please use polyfills like [isomorphic-fetch](https://github.com/matthew-andrews/isomorphic-fetch).
7595

7696
### Events
7797

78-
| Name | Params | Description |
79-
| ---- | ------ | ----------- |
80-
| play | none | Triggered when APlayer start play |
81-
| pause | none | Triggered when APlayer paused |
82-
| canplay | none | Triggered when enough data is available that APlayer can play |
83-
| playing | none | Triggered periodically when APlayer is playing |
84-
| ended | none | Triggered when APlayer ended playing |
85-
| error | none | Triggered when an error occurs |
98+
Since `v1.4.0`, Vue-APlayer emits every Media Element triggered from its inner `<audio>` element. You can [refer to MDN for the full list](https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Media_events).
99+
100+
Custom events that were supported before `v1.4.0`, which are `play` `pause` `canplay` `playing` `ended` `error`, are all deprecated now.
101+
102+
86103

87104
## Advanced
88105

89106
### Self-adapting theme color
107+
90108
Since `v1.3.0`, if you set a **Music Object**'s `theme` property to `'pic'`, Vue-APlayer will pick color from the songs cover image as theme color.
91109
Also, you can set player's `theme` prop to `'pic'`, it will apply to every song.
92110

@@ -98,9 +116,14 @@ All you need to do is adding [color-thief](https://github.com/lokesh/color-thief
98116
<script src="https://cdn.jsdelivr.net/npm/colorthief@2.0.2/src/color-thief.js"></script>
99117
```
100118

119+
120+
101121
### HLS support
122+
102123
Since `v1.3.0`, Vue-APlayer supports `*.m3u8` media as an optional functionality. Simply install [hls.js](https://github.com/video-dev/hls.js) into your project, and Vue-APlayer handles the rest.
103124

125+
126+
104127
### Slots
105128

106129
- `slot="display"`
@@ -109,6 +132,8 @@ This slot represents the content displayed on the music info panel, which by def
109132

110133
The component in this slot will receive two props: `currentMusic` and `playStat`.
111134

135+
136+
112137
## Contribute
113138

114139
Clone this repo, then **use Yarn**

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-aplayer",
3-
"version": "1.3.1",
3+
"version": "1.4.0",
44
"description": "Easy-to-config music player for Vue 2.x",
55
"main": "dist/vue-aplayer.min.js",
66
"files": [
Lines changed: 80 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
<template>
2-
<div class="aplayer-bar-wrap" @click="seekProgress" ref="barWrap">
2+
<div
3+
class="aplayer-bar-wrap"
4+
@mousedown="onThumbMouseDown"
5+
@touchstart="onThumbTouchStart"
6+
ref="barWrap"
7+
>
38
<div class="aplayer-bar">
49
<div
510
class="aplayer-loaded"
6-
:style="{width: `${Math.trunc(loadProgress * 100)}%`}">
7-
11+
:style="{width: `${loadProgress * 100}%`}">
812
</div>
913
<div
1014
class="aplayer-played"
11-
:style="{width: `${Math.trunc(playProgress * 100)}%`, background: theme}"
15+
:style="{width: `${playProgress * 100}%`, background: theme}"
1216
>
1317
<span
1418
ref="thumb"
1519
@mouseover="thumbHovered = true"
1620
@mouseout="thumbHovered = false"
17-
@mousedown="onThumbMouseDown"
18-
@touchstart="onThumbTouchStart"
1921
class="aplayer-thumb"
20-
:style="{border: '1px solid', borderColor: theme, backgroundColor: thumbHovered ? theme : '#fff'}"
22+
:style="{borderColor: theme, backgroundColor: thumbHovered ? theme : '#fff'}"
2123
>
2224
</span>
2325
</div>
@@ -26,8 +28,6 @@
2628
</template>
2729

2830
<script>
29-
30-
3131
import {getElementViewLeft} from '../utils'
3232
3333
export default {
@@ -38,15 +38,13 @@
3838
}
3939
},
4040
methods: {
41-
seekProgress (e) {
41+
onThumbMouseDown (e) {
4242
const barWidth = this.$refs.barWrap.clientWidth
4343
let percentage = (e.clientX - getElementViewLeft(this.$refs.barWrap)) / barWidth
4444
percentage = percentage > 0 ? percentage : 0
4545
percentage = percentage < 1 ? percentage : 1
46-
this.$emit('setprogress', percentage)
47-
},
48-
onThumbMouseDown () {
49-
this.$emit('dragbegin')
46+
47+
this.$emit('dragbegin', percentage)
5048
document.addEventListener('mousemove', this.onDocumentMouseMove)
5149
document.addEventListener('mouseup', this.onDocumentMouseUp)
5250
},
@@ -55,9 +53,7 @@
5553
let percentage = (e.clientX - getElementViewLeft(this.$refs.barWrap)) / barWidth
5654
percentage = percentage > 0 ? percentage : 0
5755
percentage = percentage < 1 ? percentage : 1
58-
// if (this.option.showlrc) {
59-
// this.updateLrc(parseFloat(bar.playedBar.style.width) / 100 * this.audio.duration);
60-
// }
56+
6157
this.$emit('dragging', percentage)
6258
},
6359
onDocumentMouseUp (e) {
@@ -70,8 +66,13 @@
7066
percentage = percentage < 1 ? percentage : 1
7167
this.$emit('dragend', percentage)
7268
},
73-
onThumbTouchStart () {
74-
this.$emit('dragbegin')
69+
onThumbTouchStart (e) {
70+
const barWidth = this.$refs.barWrap.clientWidth
71+
let percentage = (e.clientX - getElementViewLeft(this.$refs.barWrap)) / barWidth
72+
percentage = percentage > 0 ? percentage : 0
73+
percentage = percentage < 1 ? percentage : 1
74+
75+
this.$emit('dragbegin', percentage)
7576
document.addEventListener('touchmove', this.onDocumentTouchMove)
7677
document.addEventListener('touchend', this.onDocumentTouchEnd)
7778
},
@@ -81,9 +82,7 @@
8182
let percentage = (touch.clientX - getElementViewLeft(this.$refs.barWrap)) / barWidth
8283
percentage = percentage > 0 ? percentage : 0
8384
percentage = percentage < 1 ? percentage : 1
84-
// if (this.option.showlrc) {
85-
// this.updateLrc(parseFloat(bar.playedBar.style.width) / 100 * this.audio.duration);
86-
// }
85+
8786
this.$emit('dragging', percentage)
8887
},
8988
onDocumentTouchEnd (e) {
@@ -100,3 +99,62 @@
10099
},
101100
}
102101
</script>
102+
<style lang="scss">
103+
104+
.aplayer-bar-wrap {
105+
margin: 0 0 0 5px;
106+
padding: 4px 0;
107+
cursor: pointer !important;
108+
flex: 1;
109+
110+
.aplayer-bar {
111+
position: relative;
112+
height: 2px;
113+
width: 100%;
114+
background: #cdcdcd;
115+
116+
.aplayer-loaded {
117+
position: absolute;
118+
left: 0;
119+
top: 0;
120+
bottom: 0;
121+
background: #aaa;
122+
height: 2px;
123+
transition: all 0.5s ease;
124+
125+
will-change: width;
126+
}
127+
128+
.aplayer-played {
129+
position: absolute;
130+
left: 0;
131+
top: 0;
132+
bottom: 0;
133+
height: 2px;
134+
transition: background-color .3s;
135+
will-change: width;
136+
137+
.aplayer-thumb {
138+
position: absolute;
139+
top: 0;
140+
right: 5px;
141+
margin-top: -5px;
142+
margin-right: -10px;
143+
width: 10px;
144+
height: 10px;
145+
border: 1px solid;
146+
transform: scale(.8);
147+
will-change: transform;
148+
transition: transform 300ms, background-color .3s, border-color .3s;
149+
border-radius: 50%;
150+
background: #fff;
151+
cursor: pointer !important;
152+
153+
&:hover {
154+
transform: scale(1);
155+
}
156+
}
157+
}
158+
}
159+
}
160+
</style>

src/components/aplayer-controller-volume.vue

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
<div
1616
class="aplayer-volume"
1717
:style="{
18-
height: muted ? 0 : `${Math.trunc(volume * 100)}%`,
19-
background: theme
20-
}">
18+
height: muted ? 0 : `${Math.trunc(volume * 100)}%`,
19+
background: theme
20+
}"
21+
>
2122
</div>
2223
</div>
2324
</div>
@@ -44,7 +45,6 @@
4445
},
4546
methods: {
4647
adjustVolume (e) {
47-
4848
let percentage = (barHeight - e.clientY + getElementViewTop(this.$refs.bar)) / barHeight
4949
percentage = percentage > 0 ? percentage : 0
5050
percentage = percentage < 1 ? percentage : 1

0 commit comments

Comments
 (0)