Voice.vue
2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<script>
import BenzAMRRecorder from 'benz-amr-recorder'
export default {
name: 'Voice',
props: {
amrUrl: {
type: String,
default: '',
},
},
data() {
return {
actived: false,
// dialogVisible: false,
// audioSrc: []
}
},
computed: {},
watch: {},
created() {
this.__proto__.$isVoice || document.addEventListener('click', this.stop)
this.__proto__.$isVoice = true
},
mounted() {},
methods: {
play() {
if (this.amrUrl) {
if (this.$playRec) {
if (this.stop(true)) {
return
}
}
this.__proto__.$playRec = new BenzAMRRecorder()
this.__proto__.$playRecSymbole = this.amrUrl
this.$playRec.initWithUrl(this.amrUrl).then(() => {
this.actived = true
this.$playRec.play()
this.$playRec.onEnded(() => {
this.actived = false
})
console.log('amr 时长:' + this.$playRec.getDuration())
})
// .catch((e) => {
// this.$message.error('播放录音失败,或文件损坏')
// })
}
// this.audioSrc = [JSON.parse(this.message.contact)[type]]
},
//停止播放
stop(noset) {
if (this.$playRec && this.$playRec.isPlaying()) {
this.$playRec.stop()
if (!noset || this.__proto__.$playRecSymbole === this.amrUrl) {
this.__proto__.$playRecSymbole = ''
return true
}
}
},
// close() {
// this.dialogVisible = false
// const mp3 = this.$refs.AudioPlayer
// mp3.pause()
// },
// onBeforePlay(next) {
// next() // 开始播放
// }
},
}
</script>
<template>
<div>
<i
:class="['el-icon-microphone', actived && 'actived']"
style="font-size: 40px; color: var(--color)"
@click.stop="play('attachment')"></i>
<!-- <AudioPlayer
:audio-list="audioSrc"
ref="AudioPlayer"
:before-play="onBeforePlay"
/> -->
<!-- <el-dialog v-if="audioSrc[0]" :visible.sync="dialogVisible" width="30%" @close="close">
<div class="shabowboxvidoe shabowboxaudio">
<audio controls>
<source :src="audioSrc[0]" type="audio/mpeg" />
</audio>
</div>
<span slot="footer" class="dialog-footer"> </span>
</el-dialog> -->
</div>
</template>
<style lang="scss" scoped>
@keyframes play {
from {
// color: red;
}
to {
color: red;
}
}
.actived {
animation: play 1s infinite alternate;
}
</style>