diff --git a/src/apps/AppBroadcast1/LiveBroadcast.vue b/src/apps/AppBroadcast1/LiveBroadcast.vue index c98b2b2b..6c782242 100644 --- a/src/apps/AppBroadcast1/LiveBroadcast.vue +++ b/src/apps/AppBroadcast1/LiveBroadcast.vue @@ -14,12 +14,12 @@

喊话记录

-
+
- - - 23" + + + {{ item.duration }}"
@@ -94,7 +94,10 @@ counterDownTime: 0, time: '00:00:00', timingTimeout: null, - equipmentList: [] + equipmentList: [], + recordList: [], + innerAudioContext: null, + currIndex: -1 } }, @@ -111,16 +114,30 @@ }, mounted () { - const close = document.querySelector('.close') - this.x = close.offsetLeft - this.y = close.offsetTop - this.w = close.clientWidth - this.h = close.clientHeight + this.$nextTick(() => { + const close = document.querySelector('.close') + this.x = close.offsetLeft + this.y = close.offsetTop + this.w = close.clientWidth + this.h = close.clientHeight + }) }, onLoad () { + this.innerAudioContext = uni.createInnerAudioContext() + this.innerAudioContext.autoplay = true + this.innerAudioContext.onEnded(() => { + if (this.currIndex > -1) { + this.$set(this.recordList[this.currIndex], 'isPlay', false) + // this.innerAudioContext.destroy() + this.currIndex = -1 + } + }) + this.innerAudioContext.onPlay(() => { + this.$set(this.recordList[this.currIndex], 'isPlay', true) + }) + uni.$on('chooseEquipment', e => { - console.log(e) this.equipmentList = e.equipmentList }) }, @@ -173,6 +190,24 @@ }, 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) { + this.currIndex = index + + this.$nextTick(() => { + this.innerAudioContext.src = url + }) + }, + stop (isCancel) { this.counterDownTime = 0 clearTimeout(this.timingTimeout) @@ -180,11 +215,32 @@ this.recorder.close() this.recorder = null - if (!isCancel) { - this.blobFile = blob + if (isCancel) { + return false } this.time = '00:00:00' + // this.blobToDataURI(blob).then(res => { + // console.log(res, (window.URL || webkitURL).createObjectURL(blob), '时长:' + duration + 'ms') + // }) + this.recordList.push({ + src: (window.URL || webkitURL).createObjectURL(blob), + isPlay: false, + duration: (duration / 1000).toFixed(0) + }) + + + let formData = {} + formData = new FormData() + formData.append('file', blob) + + this.$http.post(`/app/appdlbresource/uploadDlbFile`, formData).then(res => { + if (res.code === 0) { + + } + }) + this.isShowRecord = true + this.isShow = false console.log(blob, (window.URL || webkitURL).createObjectURL(blob), '时长:' + duration + 'ms') }, msg => { console.log('录音失败:' + msg)