Commit cf037571 by xinla

Voice

1 parent 10037ac5
<script> <script>
import BenzAMRRecorder from 'benz-amr-recorder' import BenzAMRRecorder from 'benz-amr-recorder'
let $isVoice = undefined
let $playRec = undefined
let $playRecSymbole = undefined
export default { export default {
name: 'Voice', name: 'Voice',
props: { props: {
...@@ -18,27 +21,27 @@ export default { ...@@ -18,27 +21,27 @@ export default {
computed: {}, computed: {},
watch: {}, watch: {},
created() { created() {
this.__proto__.$isVoice || document.addEventListener('click', this.stop) $isVoice || document.addEventListener('click', this.stop)
this.__proto__.$isVoice = true $isVoice = true
}, },
mounted() {}, mounted() {},
methods: { methods: {
play() { play() {
if (this.amrUrl) { if (this.amrUrl) {
if (this.$playRec) { if ($playRec) {
if (this.stop(true)) { if (this.stop(true)) {
return return
} }
} }
this.__proto__.$playRec = new BenzAMRRecorder() $playRec = new BenzAMRRecorder()
this.__proto__.$playRecSymbole = this.amrUrl $playRecSymbole = this.amrUrl
this.$playRec.initWithUrl(this.amrUrl).then(() => { $playRec.initWithUrl(this.amrUrl).then(() => {
this.actived = true this.actived = true
this.$playRec.play() $playRec.play()
this.$playRec.onEnded(() => { $playRec.onEnded(() => {
this.actived = false this.actived = false
}) })
console.log('amr 时长:' + this.$playRec.getDuration()) console.log('amr 时长:' + $playRec.getDuration())
}) })
// .catch((e) => { // .catch((e) => {
// this.$message.error('播放录音失败,或文件损坏') // this.$message.error('播放录音失败,或文件损坏')
...@@ -48,10 +51,10 @@ export default { ...@@ -48,10 +51,10 @@ export default {
}, },
//停止播放 //停止播放
stop(noset) { stop(noset) {
if (this.$playRec && this.$playRec.isPlaying()) { if ($playRec && $playRec.isPlaying()) {
this.$playRec.stop() $playRec.stop()
if (!noset || this.__proto__.$playRecSymbole === this.amrUrl) { if (!noset || $playRecSymbole === this.amrUrl) {
this.__proto__.$playRecSymbole = '' $playRecSymbole = ''
return true return true
} }
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!