This commit is contained in:
liuye
2022-06-22 10:25:07 +08:00
7 changed files with 34 additions and 39 deletions

View File

@@ -129,6 +129,7 @@
destroyed () {
document.body.removeEventListener('touchmove', this.bindEvent)
this.recorder.close()
},
onLoad () {
@@ -149,6 +150,19 @@
uni.$on('chooseEquipment', e => {
this.equipmentList = e.equipmentList
})
this.recorder = Recorder({
type: 'mp3',
sampleRate: 16000,
bitRate: 16,
onProcess(buffers, powerLevel, bufferDuration, bufferSampleRate, newBufferIdx, asyncEnd) {
//可利用extensions/waveview.js扩展实时绘制波形
}
})
this.recorder.open((e) => {
console.log(e)
}, e => {
console.log(e)
})
},
methods: {
@@ -157,6 +171,8 @@
},
onLongtap () {
this.time = 60
if (!this.equipmentList.length) {
return this.$u.toast('请选择播发设备')
}
@@ -174,43 +190,23 @@
},
record () {
this.duration = 0
this.recorder = Recorder({
type: 'mp3',
sampleRate: 16000,
bitRate: 16,
onProcess(buffers, powerLevel, bufferDuration, bufferSampleRate, newBufferIdx, asyncEnd) {
//可利用extensions/waveview.js扩展实时绘制波形
}
})
this.recorder.open(() => {
this.recorder.start()
this.timing()
})
this.recorder.start()
this.timing()
},
timing () {
this.time = this.time - 1
if (this.time === 0) {
this.stop()
return false
}
this.time = this.time - 1
this.timingTimeout = setTimeout(() => {
this.timing()
}, 1000)
},
blobToDataURI(blob) {
return new Promise((resolve) => {
var reader = new FileReader()
reader.readAsDataURL(blob)
reader.onload = function (e) {
resolve(e.target.result)
}
})
},
play (url, index) {
if (this.currIndex === index) {
this.innerAudioContext.destroy()
@@ -237,9 +233,6 @@
stop (isCancel) {
clearTimeout(this.timingTimeout)
this.recorder.stop((blob, duration) => {
this.recorder.close()
this.recorder = null
if (isCancel) {
this.time = 60
return false
@@ -275,21 +268,20 @@
this.isShow = false
}).catch(() => {
this.isShow = false
uni.hideLoading()
})
} else {
this.isShow = false
}
}).catch(() => {
uni.hideLoading()
this.isShow = false
})
this.time = 60
console.log(blob, (window.URL || webkitURL).createObjectURL(blob), '时长:' + duration + 'ms')
}, msg => {
console.log('录音失败:' + msg)
this.recorder.close()
this.isShow = false
this.recorder = null
})
},

View File

@@ -36,6 +36,8 @@
import { mapState } from 'vuex'
export default {
name: "selectEquipment",
appName: '选择设备',
data() {
return {
areaId: '',