fix: bug
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<view class="talking-info-es" v-if="intrctWay === '02'">
|
||||
<view :class="['talking-gif', 'is-play']">
|
||||
<view :class="['talking-gif', isPlaying ?'is-play':'']">
|
||||
<CommonLoading color="#fff" v-show="voiceLoading" />
|
||||
</view>
|
||||
<view class="right-time">{{ voiceTime }}</view>
|
||||
@@ -14,10 +14,12 @@
|
||||
</view>
|
||||
<view class="btns-cont">
|
||||
<view class="play-btn">
|
||||
<image class="icon" @click="playVoice" src="@/static/images/course/play-blue.png"
|
||||
<image class="icon" @click="playVoice" src="@/static/images/course/play-blue.png" v-show="!isPlaying"
|
||||
style="width: 100%; height: 100%"></image>
|
||||
<image class="icon" v-show="isPlaying" @click.stop="pauseVoice" src="@/static/images/course/stop-blue.png"
|
||||
style="width: 100%;height: 100%;"></image>
|
||||
</view>
|
||||
<view class="text-btn" @click.stop="translateVoice()">文</view>
|
||||
<!-- <view class="text-btn" @click.stop="translateVoice()">文</view> -->
|
||||
</view>
|
||||
</view>
|
||||
<!-- 01纯文字 -->
|
||||
@@ -80,7 +82,6 @@
|
||||
} = toRefs(props);
|
||||
|
||||
const intrctWay = computed(() => {
|
||||
console.log('props.intrctWay', props.intrctWay);
|
||||
return props.intrctWay;
|
||||
});
|
||||
const emit = defineEmits(['changePlay', 'buutton_click']);
|
||||
@@ -91,6 +92,12 @@
|
||||
immediate: true
|
||||
}
|
||||
);
|
||||
watch(() => props.activeVoiceId, (val) => {
|
||||
if (val != dataInfo.value.ossAddr) {
|
||||
pauseVoice();
|
||||
isPlaying.value = false
|
||||
}
|
||||
})
|
||||
// 声音播放初始化
|
||||
const talkVoiceObj = ref(null);
|
||||
|
||||
@@ -107,21 +114,21 @@
|
||||
});
|
||||
onMounted(() => {
|
||||
initVoice();
|
||||
watch(
|
||||
() => props.dataInfo.ossAddr,
|
||||
(val) => {
|
||||
if (val) {
|
||||
initVoice();
|
||||
}
|
||||
}, {
|
||||
deep: true,
|
||||
immediate: true
|
||||
}
|
||||
);
|
||||
});
|
||||
onUnload(() => {
|
||||
pauseVoice();
|
||||
});
|
||||
watch(
|
||||
() => props.dataInfo.ossAddr,
|
||||
(val) => {
|
||||
if (val) {
|
||||
initVoice();
|
||||
}
|
||||
}, {
|
||||
deep: true,
|
||||
immediate: true
|
||||
}
|
||||
);
|
||||
|
||||
// 按钮点击
|
||||
const buutton_click = (type) => {
|
||||
@@ -134,7 +141,7 @@
|
||||
emit('changePlay', '');
|
||||
};
|
||||
const playVoice = () => {
|
||||
emit('changePlay', unref(dataInfo)?.id);
|
||||
emit('changePlay', unref(dataInfo)?.ossAddr);
|
||||
if (talkVoiceObj.value && talkVoiceObj.value.src) {
|
||||
talkVoiceObj.value.play();
|
||||
return;
|
||||
@@ -142,7 +149,8 @@
|
||||
talkVoiceObj.value.src = '';
|
||||
if (unref(dataInfo).ossAddr) {
|
||||
setTimeout(() => {
|
||||
talkVoiceObj.value.src = unref(dataInfo).ossAddr;
|
||||
talkVoiceObj.value.src =
|
||||
'http://25.18.122.92:9786/traoss/tras3/show//S3F0250181221042025091814253800004818633' //unref(dataInfo).ossAddr;
|
||||
talkVoiceObj.value.play();
|
||||
isPlaying.value = true;
|
||||
}, 100);
|
||||
@@ -151,13 +159,42 @@
|
||||
};
|
||||
const initVoice = () => {
|
||||
talkVoiceObj.value = uni.createInnerAudioContext();
|
||||
let prevTime = -1;
|
||||
talkVoiceObj.value.onEnded(() => {
|
||||
emit('changePlay', '');
|
||||
prevTime = -1;
|
||||
talkVoiceObj.value.src = '';
|
||||
});
|
||||
talkVoiceObj.value.onError(() => {
|
||||
talkVoiceObj.value.onStop(() => {
|
||||
emit('changePlay', '');
|
||||
prevTime = -1;
|
||||
talkVoiceObj.value.src = '';
|
||||
});
|
||||
talkVoiceObj.value.onPause(() => {
|
||||
prevTime = talkVoiceObj.value.currentTime;
|
||||
emit('changePlay', '');
|
||||
});
|
||||
talkVoiceObj.value.onError(() => {
|
||||
prevTime = -1;
|
||||
emit('changePlay', '');
|
||||
});
|
||||
talkVoiceObj.value.onPlay(() => {
|
||||
prevTime = talkVoiceObj.value.currentTime;
|
||||
emit('changePlay', unref(dataInfo)?.ossAddr);
|
||||
});
|
||||
talkVoiceObj.value.onTimeUpdate(() => {
|
||||
if (props.activeVoiceId === unref(dataInfo)?.ossAddr) {
|
||||
setTimeout(() => {
|
||||
if (talkVoiceObj.value.currentTime !== prevTime) {
|
||||
if (talkVoiceObj.value.currentTime > 0) {
|
||||
prevTime = talkVoiceObj.value.currentTime;
|
||||
}
|
||||
} else {
|
||||
emit('changePlay', '');
|
||||
}
|
||||
}, 500);
|
||||
}
|
||||
});
|
||||
if (unref(dataInfo).intrctWay === '02') {
|
||||
itemVoice.value = unref(dataInfo).ossAddr;
|
||||
talkVoiceObj.value.src = itemVoice.value;
|
||||
@@ -202,8 +239,8 @@
|
||||
padding-left: 168rpx;
|
||||
|
||||
&.is-play {
|
||||
background: url(@/static/images/course/voice-white.gif) no-repeat;
|
||||
background-size: contain;
|
||||
background: url(@/static/images/course/voice-white.gif) no-repeat !important;
|
||||
background-size: contain !important;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user