语音组件优化,下载过程使用RC接口,播放优化
This commit is contained in:
@@ -48,27 +48,25 @@
|
|||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
.name {
|
.name {
|
||||||
font-size: 24rpx;
|
font-size: 24rpx;
|
||||||
line-height: 34rpx;
|
|
||||||
color: $text-gray-m;
|
color: $text-gray-m;
|
||||||
padding-bottom: 10rpx;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.msg--image {
|
.msg--image {
|
||||||
// padding: 20rpx;
|
.img {
|
||||||
|
width: 180rpx;
|
||||||
|
}
|
||||||
|
|
||||||
&.left {
|
&.left {
|
||||||
border-radius: 0 20rpx 20rpx 20rpx;
|
.img {
|
||||||
// background: white;
|
border-radius: 0 10rpx 10rpx 10rpx;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
&.right {
|
&.right {
|
||||||
border-radius: 20rpx 0 20rpx 20rpx;
|
.img {
|
||||||
// background: #34CE98;
|
border-radius: 10rpx 0 10rpx 10rpx;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.img {
|
|
||||||
width: 150rpx;
|
|
||||||
border-radius: 10rpx;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -32,10 +32,10 @@
|
|||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
.msg--text {
|
.msg--text {
|
||||||
.name {
|
.name {
|
||||||
font-size: 26rpx;
|
font-size: 24rpx;
|
||||||
color: $text-gray-m;
|
color: $text-gray-m;
|
||||||
display: inline-block;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.im--text {
|
.im--text {
|
||||||
max-width: 508rpx;
|
max-width: 508rpx;
|
||||||
padding: 20rpx;
|
padding: 20rpx;
|
||||||
@@ -44,10 +44,12 @@
|
|||||||
color: $text-color;
|
color: $text-color;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
word-break: break-all;
|
word-break: break-all;
|
||||||
|
|
||||||
&.left {
|
&.left {
|
||||||
border-radius: 0 20rpx 20rpx 20rpx;
|
border-radius: 0 20rpx 20rpx 20rpx;
|
||||||
background: white;
|
background: white;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.right {
|
&.right {
|
||||||
border-radius: 20rpx 0 20rpx 20rpx;
|
border-radius: 20rpx 0 20rpx 20rpx;
|
||||||
background: $main-color;
|
background: $main-color;
|
||||||
|
|||||||
@@ -1,75 +1,88 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="">
|
<view class="">
|
||||||
<text class="name" v-if="!guest && name">{{ name }}</text>
|
<text class="name" v-if="isGroup && guest">{{ contact(message.senderUserId).name }}</text>
|
||||||
<view class="msg--voice" :class="guest ? 'right': 'left'" @click="onPlayMsg">
|
<view class="msg--voice" :class="guest ? 'right': 'left'" @click="onPlayMsg">
|
||||||
<image v-if="!guest" class="icon" src="@/static/icon/audio_green.png" mode="widthFix"></image>
|
<image v-if="!guest" class="icon" src="@/static/icon/audio_green.png" mode="widthFix"></image>
|
||||||
<text class="duration">{{msg.duration}}"</text>
|
<text class="duration">{{ duration }}"</text>
|
||||||
<image v-if="guest" class="icon" src="@/static/icon/audio_white.png" mode="widthFix"></image>
|
<image v-if="guest" class="icon" src="@/static/icon/audio_white.png" mode="widthFix"></image>
|
||||||
</view>
|
</view>
|
||||||
|
<!-- <view class="">这里显示个红点,根据message.content.local是否为空的时候判断</view> -->
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import * as RongIMLib from '@/uni_modules/RongCloud-IMWrapper/js_sdk/index'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'showVoice',
|
name: 'showVoice',
|
||||||
props: {
|
props: {
|
||||||
msg: {
|
message: {
|
||||||
type: Object,
|
type: Object,
|
||||||
default: () => {
|
default: () => {
|
||||||
return {
|
return {}
|
||||||
local: '',
|
|
||||||
remote: '',
|
|
||||||
objectName: '',
|
|
||||||
duration: 0
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
name: {
|
isGroup: {
|
||||||
type: String,
|
|
||||||
default: ''
|
|
||||||
},
|
|
||||||
guest: {
|
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
default: true
|
default: false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
computed: {
|
||||||
|
duration() {
|
||||||
|
return this.message.content.duration
|
||||||
|
},
|
||||||
|
guest() {
|
||||||
|
return this.message.messageDirection == 2
|
||||||
|
|
||||||
|
},
|
||||||
|
contact() {
|
||||||
|
return function(targetId) {
|
||||||
|
return this.$store.getters.contactInfo(targetId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
// 播放语音消息
|
// 播放语音消息
|
||||||
onPlayMsg() {
|
onPlayMsg() {
|
||||||
uni.downloadFile({
|
if (this.message.content.local) {
|
||||||
url: this.msg.remote,
|
this.playMsg(this.message.content.local)
|
||||||
success: (res) => {
|
} else {
|
||||||
if (res.statusCode === 200) {
|
RongIMLib.downloadMediaMessage(this.message.messageId, {
|
||||||
let innerAudioContext = uni.createInnerAudioContext()
|
success: (path) => {
|
||||||
innerAudioContext.src = res.tempFilePath
|
this.message.content.local = path
|
||||||
if (this.audioContextPaused) {
|
this.playMsg(path)
|
||||||
innerAudioContext.play()
|
},
|
||||||
this.audioContextPaused = false
|
progress: (progress, messageId) => {},
|
||||||
return
|
cancel: (messageId) => {},
|
||||||
|
error: (errorCode, messageId) => {
|
||||||
|
// 发送错误回调
|
||||||
}
|
}
|
||||||
innerAudioContext.stop()
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
playMsg(path) {
|
||||||
|
const innerAudioContext = uni.createInnerAudioContext()
|
||||||
|
innerAudioContext.src = path
|
||||||
|
innerAudioContext.autoplay = true
|
||||||
innerAudioContext.onStop(resStop => {
|
innerAudioContext.onStop(resStop => {
|
||||||
this.audioContextPaused = true
|
innerAudioContext.destroy()
|
||||||
})
|
})
|
||||||
innerAudioContext.onError(err => {
|
innerAudioContext.onError(err => {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped lang="scss">
|
<style scoped lang="scss">
|
||||||
.name {
|
.name {
|
||||||
font-size: 24rpx;
|
font-size: 24rpx;
|
||||||
line-height: 34rpx;
|
|
||||||
color: $text-gray-m;
|
color: $text-gray-m;
|
||||||
}
|
}
|
||||||
|
|
||||||
.msg--voice {
|
.msg--voice {
|
||||||
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
|||||||
@@ -10,8 +10,7 @@
|
|||||||
<u-avatar class="avatar" @click="toUser(item)" :size="avatarSize" shape="square"
|
<u-avatar class="avatar" @click="toUser(item)" :size="avatarSize" shape="square"
|
||||||
:src="contact(item.senderUserId).portraitUrl" />
|
:src="contact(item.senderUserId).portraitUrl" />
|
||||||
<view class="msg">
|
<view class="msg">
|
||||||
<show-voice v-if="item.objectName === 'RC:HQVCMsg'" :guest="item.messageDirection == 1"
|
<show-voice v-if="item.objectName === 'RC:HQVCMsg'" :message="item" isGroup />
|
||||||
:msg="item.content" :name="contact(item.senderUserId).name" />
|
|
||||||
<show-image v-if="item.objectName === 'RC:ImgMsg'" :guest="item.messageDirection == 1"
|
<show-image v-if="item.objectName === 'RC:ImgMsg'" :guest="item.messageDirection == 1"
|
||||||
:msg="item.content" :name="contact(item.senderUserId).name" />
|
:msg="item.content" :name="contact(item.senderUserId).name" />
|
||||||
<show-text v-if="item.objectName === 'RC:TxtMsg'" :guest="item.messageDirection == 1"
|
<show-text v-if="item.objectName === 'RC:TxtMsg'" :guest="item.messageDirection == 1"
|
||||||
|
|||||||
@@ -11,8 +11,7 @@
|
|||||||
@click="showUser(item.senderUserId, item.messageDirection)"
|
@click="showUser(item.senderUserId, item.messageDirection)"
|
||||||
:src="contact(item.senderUserId).portraitUrl" />
|
:src="contact(item.senderUserId).portraitUrl" />
|
||||||
<view class="msg">
|
<view class="msg">
|
||||||
<show-voice v-if="item.objectName === 'RC:HQVCMsg'" :guest="item.messageDirection == 1"
|
<show-voice v-if="item.objectName === 'RC:HQVCMsg'" :message="item" />
|
||||||
:msg="item.content" />
|
|
||||||
<show-image v-if="item.objectName === 'RC:ImgMsg'" :guest="item.messageDirection == 1"
|
<show-image v-if="item.objectName === 'RC:ImgMsg'" :guest="item.messageDirection == 1"
|
||||||
:msg="item.content" />
|
:msg="item.content" />
|
||||||
<show-text v-if="item.objectName === 'RC:TxtMsg'" :guest="item.messageDirection == 1"
|
<show-text v-if="item.objectName === 'RC:TxtMsg'" :guest="item.messageDirection == 1"
|
||||||
|
|||||||
Reference in New Issue
Block a user