This commit is contained in:
parent
8e54160b67
commit
6a6a855373
|
@ -92,17 +92,13 @@ async function handleCopy() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const playStatus = ref('end')
|
const playStatus = ref('end')
|
||||||
const playStatus = ref('end')
|
|
||||||
let playing = 0
|
let playing = 0
|
||||||
let sok = false
|
let sok = false
|
||||||
let sok = false
|
|
||||||
async function radioPlay() {
|
async function radioPlay() {
|
||||||
console.log('播放', props.mp3)
|
console.log('播放', props.mp3)
|
||||||
audioElements.length = 0
|
audioElements.length = 0
|
||||||
audioElements.length = 0
|
|
||||||
const socket = new WebSocket('wss://chat.lihaink.cn/zhanti/tts')
|
const socket = new WebSocket('wss://chat.lihaink.cn/zhanti/tts')
|
||||||
sok = true
|
sok = true
|
||||||
sok = true
|
|
||||||
|
|
||||||
const promise = () => {
|
const promise = () => {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
|
@ -117,8 +113,6 @@ async function radioPlay() {
|
||||||
|
|
||||||
await promise()
|
await promise()
|
||||||
|
|
||||||
socket.onerror = (event: any) => { sok = false; console.log('连接错误事件: ', event); console.log('sok状态', sok);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 监听WebSocket关闭事件
|
// 监听WebSocket关闭事件
|
||||||
socket.onclose = (event: any) => {
|
socket.onclose = (event: any) => {
|
||||||
|
@ -127,9 +121,6 @@ async function radioPlay() {
|
||||||
console.log('sok状态', sok);
|
console.log('sok状态', sok);
|
||||||
}
|
}
|
||||||
|
|
||||||
// socket.send(JSON.stringify({
|
|
||||||
// data: '快。科。技0月12。日消息。不宣而发的。华为Mate 60在上架官方商城后。直到现在都处于一机难求的状态。由于Mate 60系列的爆火。华为也是将明年的预计手机出货量翻倍到了7000万台。',
|
|
||||||
// }))
|
|
||||||
// socket.send(JSON.stringify({
|
// socket.send(JSON.stringify({
|
||||||
// data: '快。科。技0月12。日消息。不宣而发的。华为Mate 60在上架官方商城后。直到现在都处于一机难求的状态。由于Mate 60系列的爆火。华为也是将明年的预计手机出货量翻倍到了7000万台。',
|
// data: '快。科。技0月12。日消息。不宣而发的。华为Mate 60在上架官方商城后。直到现在都处于一机难求的状态。由于Mate 60系列的爆火。华为也是将明年的预计手机出货量翻倍到了7000万台。',
|
||||||
// }))
|
// }))
|
||||||
|
@ -138,7 +129,6 @@ async function radioPlay() {
|
||||||
data: props.text,
|
data: props.text,
|
||||||
}))
|
}))
|
||||||
playStatus.value = 'playing'
|
playStatus.value = 'playing'
|
||||||
playStatus.value = 'playing'
|
|
||||||
let i = 0
|
let i = 0
|
||||||
// 监听WebSocket接收消息事件
|
// 监听WebSocket接收消息事件
|
||||||
socket.onmessage = (event: any) => {
|
socket.onmessage = (event: any) => {
|
||||||
|
@ -178,7 +168,6 @@ const onAudioEnd = (index: any) => {
|
||||||
audioElements[playing].play()
|
audioElements[playing].play()
|
||||||
}
|
}
|
||||||
else { playStatus.value = 'end' }
|
else { playStatus.value = 'end' }
|
||||||
else { playStatus.value = 'end' }
|
|
||||||
}
|
}
|
||||||
// 创建音频对象的数组
|
// 创建音频对象的数组
|
||||||
const audioElements = reactive([])
|
const audioElements = reactive([])
|
||||||
|
@ -189,25 +178,17 @@ const playAudio = (playIndex: any) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(() => audioElements.length, (newVal, oldVal) => {
|
watch(() => audioElements.length, (newVal, oldVal) => {
|
||||||
if (playStatus.value == 'pause')
|
|
||||||
return
|
|
||||||
if (newVal > playing && playFlag == false && newVal > 0) {
|
|
||||||
if (playStatus.value == 'pause')
|
if (playStatus.value == 'pause')
|
||||||
return
|
return
|
||||||
if (newVal > playing && playFlag == false && newVal > 0) {
|
if (newVal > playing && playFlag == false && newVal > 0) {
|
||||||
audioElements[playing].play()
|
audioElements[playing].play()
|
||||||
playStatus.value = 'playing'
|
playStatus.value = 'playing'
|
||||||
}
|
}
|
||||||
playStatus.value = 'playing'
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
let pauseIndex = -1
|
|
||||||
let pauseIndex = -1
|
let pauseIndex = -1
|
||||||
// 暂停音频
|
// 暂停音频
|
||||||
const pauseAudio = () => {
|
const pauseAudio = () => {
|
||||||
pauseIndex = playing + 0
|
|
||||||
playStatus.value = 'pause'
|
|
||||||
pauseIndex = playing + 0
|
pauseIndex = playing + 0
|
||||||
playStatus.value = 'pause'
|
playStatus.value = 'pause'
|
||||||
for (let i = 0; i < audioElements.length; i++)
|
for (let i = 0; i < audioElements.length; i++)
|
||||||
|
@ -218,11 +199,6 @@ const noPauseAudio = () => {
|
||||||
audioElements[pauseIndex].play()
|
audioElements[pauseIndex].play()
|
||||||
pauseIndex = -1
|
pauseIndex = -1
|
||||||
}
|
}
|
||||||
const noPauseAudio = () => {
|
|
||||||
playStatus.value = 'playing'
|
|
||||||
audioElements[pauseIndex].play()
|
|
||||||
pauseIndex = -1
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
Loading…
Reference in New Issue