15
15
<i v-show =" !microphone.enabled" class =" material-icons off" >mic_off</i >
16
16
<i v-show =" microphone.enabled" class =" material-icons" >mic</i >
17
17
</div >
18
- <div class =" button playlist" @click =" showPlaylist = !showPlaylist" :class =" { off: !showPlaylist }" >
18
+ <div
19
+ class =" button playlist"
20
+ @click =" showPlaylist = !showPlaylist"
21
+ :class =" { off: !showPlaylist }"
22
+ >
19
23
<i class =" material-icons" >queue_music</i >
20
24
<transition name =" playlist" >
21
25
<div class =" list" v-show =" showPlaylist" >
35
39
</template >
36
40
37
41
<script >
42
+ import Utils from ' @/js/Utils'
43
+
38
44
export default {
39
45
props: {
40
46
audio: {
@@ -70,6 +76,7 @@ export default {
70
76
playlistNext () {
71
77
this .playlist .next ()
72
78
},
79
+
73
80
timeUpdate () {
74
81
let p = this .audio .currentTime / this .audio .duration
75
82
let bar = document .querySelector (' .progress > .scrubber' )
@@ -79,42 +86,50 @@ export default {
79
86
this .timePassed = t
80
87
this .timeRemaining = Math .floor (this .audio .duration ) - t
81
88
},
89
+
82
90
togglePlay () {
83
91
if (this .audio .ended && this .playlist .hasNext ()) this .playlist .next ()
84
92
85
93
if (this .audio .paused && this .audio .readyState == 4 ) this .audio .play ()
86
94
else this .audio .pause ()
87
95
},
96
+
88
97
updatePaused () {
89
98
this .paused = this .audio .paused
90
99
},
100
+
91
101
stopMicOnPlay () {
92
102
if (this .microphone .enabled ) this .microphone .toggle ()
93
103
},
104
+
94
105
scrub (e ) {
95
106
let { progress } = this .$refs
96
107
let p = e .offsetX / progress .offsetWidth
97
108
let paused = this .audio .paused
98
109
this .audio .currentTime = p * this .audio .duration
99
110
if (paused) this .audio .pause ()
100
111
},
112
+
101
113
mousedown (e ) {
102
114
if (! this .audio .src ) return
103
115
this .seeking = e .pageX - e .offsetX
104
116
this .scrub (e)
105
117
},
118
+
106
119
mousemove (e ) {
107
120
if (this .seeking ) {
108
121
let { progress } = this .$refs
109
122
let offset = e .pageX - this .seeking
110
- offset = Math . max ( 0 , Math . min ( progress .offsetWidth , offset) )
123
+ offset = Utils . clamp (offset, 0 , progress .offsetWidth )
111
124
if (offset == progress .offsetWidth ) this .seeking = false
112
125
this .scrub ({ offsetX: offset })
113
126
}
114
127
},
128
+
115
129
mouseup () {
116
130
this .seeking = false
117
131
},
132
+
118
133
keyup (e ) {
119
134
e .preventDefault ()
120
135
switch (e .keyCode ) {
0 commit comments