This commit is contained in:
weipengfei 2023-10-13 10:54:40 +08:00
commit 8e54160b67
1 changed files with 23 additions and 0 deletions

View File

@ -92,13 +92,17 @@ async function handleCopy() {
}
}
const playStatus = ref('end')
const playStatus = ref('end')
let playing = 0
let sok = false
let sok = false
async function radioPlay() {
console.log('播放', props.mp3)
audioElements.length = 0
audioElements.length = 0
const socket = new WebSocket('wss://chat.lihaink.cn/zhanti/tts')
sok = true
sok = true
const promise = () => {
return new Promise((resolve, reject) => {
@ -123,13 +127,18 @@ async function radioPlay() {
console.log('sok状态', sok);
}
// socket.send(JSON.stringify({
// data: '012Mate 60Mate 607000',
// }))
// socket.send(JSON.stringify({
// data: '012Mate 60Mate 607000',
// }))
socket.send(JSON.stringify({
data: props.text,
data: props.text,
}))
playStatus.value = 'playing'
playStatus.value = 'playing'
let i = 0
// WebSocket
socket.onmessage = (event: any) => {
@ -169,6 +178,7 @@ const onAudioEnd = (index: any) => {
audioElements[playing].play()
}
else { playStatus.value = 'end' }
else { playStatus.value = 'end' }
}
//
const audioElements = reactive([])
@ -179,17 +189,25 @@ const playAudio = (playIndex: any) => {
}
watch(() => audioElements.length, (newVal, oldVal) => {
if (playStatus.value == 'pause')
return
if (newVal > playing && playFlag == false && newVal > 0) {
if (playStatus.value == 'pause')
return
if (newVal > playing && playFlag == false && newVal > 0) {
audioElements[playing].play()
playStatus.value = 'playing'
}
playStatus.value = 'playing'
}
})
let pauseIndex = -1
let pauseIndex = -1
//
const pauseAudio = () => {
pauseIndex = playing + 0
playStatus.value = 'pause'
pauseIndex = playing + 0
playStatus.value = 'pause'
for (let i = 0; i < audioElements.length; i++)
@ -200,6 +218,11 @@ const noPauseAudio = () => {
audioElements[pauseIndex].play()
pauseIndex = -1
}
const noPauseAudio = () => {
playStatus.value = 'playing'
audioElements[pauseIndex].play()
pauseIndex = -1
}
</script>
<template>