mirror of
https://github.com/kevin-DL/vue-audio-recorder.git
synced 2026-01-11 19:04:28 +00:00
Add decorator for all player buttons
This commit is contained in:
@@ -88,20 +88,20 @@
|
|||||||
id="download"
|
id="download"
|
||||||
class="ar-icon ar-icon__sm"
|
class="ar-icon ar-icon__sm"
|
||||||
name="download"
|
name="download"
|
||||||
@click.native="download"/>
|
@click.native="decorator(download)"/>
|
||||||
|
|
||||||
<icon-button
|
<icon-button
|
||||||
id="play"
|
id="play"
|
||||||
class="ar-icon ar-icon__lg ar-player__play"
|
class="ar-icon ar-icon__lg ar-player__play"
|
||||||
:name="playBtnIcon"
|
:name="playBtnIcon"
|
||||||
:class="{'ar-player__play--active': isPlaying}"
|
:class="{'ar-player__play--active': isPlaying}"
|
||||||
@click.native="playback"/>
|
@click.native="decorator(playback)"/>
|
||||||
|
|
||||||
<icon-button
|
<icon-button
|
||||||
id="upload"
|
id="upload"
|
||||||
class="ar-icon ar-icon__sm"
|
class="ar-icon ar-icon__sm"
|
||||||
name="save"
|
name="save"
|
||||||
@click.native="upload"/>
|
@click.native="decorator(upload)"/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="ar-player-bar">
|
<div class="ar-player-bar">
|
||||||
@@ -163,22 +163,23 @@
|
|||||||
this.player.addEventListener('timeupdate', this._onTimeUpdate)
|
this.player.addEventListener('timeupdate', this._onTimeUpdate)
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
|
audioSource () {
|
||||||
|
let url = this.src || this.record.url
|
||||||
|
if (url) {
|
||||||
|
return url
|
||||||
|
} else {
|
||||||
|
this._resetProgress()
|
||||||
|
}
|
||||||
|
},
|
||||||
playBtnIcon () {
|
playBtnIcon () {
|
||||||
return this.isPlaying ? 'pause' : 'play'
|
return this.isPlaying ? 'pause' : 'play'
|
||||||
},
|
},
|
||||||
audioSource () {
|
|
||||||
return this.src || this.record.url
|
|
||||||
},
|
|
||||||
playerUniqId () {
|
playerUniqId () {
|
||||||
return `audio-player${this._uid}`
|
return `audio-player${this._uid}`
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
playback () {
|
playback () {
|
||||||
if (!this.audioSource) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.isPlaying) {
|
if (this.isPlaying) {
|
||||||
this.player.pause()
|
this.player.pause()
|
||||||
} else {
|
} else {
|
||||||
@@ -188,10 +189,6 @@
|
|||||||
this.isPlaying = !this.isPlaying
|
this.isPlaying = !this.isPlaying
|
||||||
},
|
},
|
||||||
upload () {
|
upload () {
|
||||||
if (!this.audioSource) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.startUpload) {
|
if (this.startUpload) {
|
||||||
this.startUpload()
|
this.startUpload()
|
||||||
}
|
}
|
||||||
@@ -216,18 +213,27 @@
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
download () {
|
download () {
|
||||||
if (!this.audioSource) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
let link = document.createElement('a')
|
let link = document.createElement('a')
|
||||||
link.href = this.record.url
|
link.href = this.record.url
|
||||||
link.download = 'record.wav'
|
link.download = 'record.wav'
|
||||||
link.click()
|
link.click()
|
||||||
},
|
},
|
||||||
|
decorator (func) {
|
||||||
|
if (!this.audioSource) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
func()
|
||||||
|
},
|
||||||
_resetProgress () {
|
_resetProgress () {
|
||||||
this.isPlaying = false
|
if (this.isPlaying) {
|
||||||
this.progress = 0
|
this.player.pause()
|
||||||
|
}
|
||||||
|
setTimeout(() => {
|
||||||
|
this.duration = convertTimeMMSS(0)
|
||||||
|
this.playedTime = convertTimeMMSS(0)
|
||||||
|
this.progress = 0
|
||||||
|
this.isPlaying = false
|
||||||
|
}, 0)
|
||||||
},
|
},
|
||||||
_onTimeUpdate () {
|
_onTimeUpdate () {
|
||||||
this.playedTime = convertTimeMMSS(this.player.currentTime)
|
this.playedTime = convertTimeMMSS(this.player.currentTime)
|
||||||
|
|||||||
Reference in New Issue
Block a user