fix: 恢复简单播放逻辑,移除复杂的错误处理
This commit is contained in:
BIN
logs/server.log
BIN
logs/server.log
Binary file not shown.
@@ -545,25 +545,6 @@
|
||||
let currentVoice = 'zh-CN-XiaoxiaoNeural';
|
||||
let autoPlay = true; // 自动播放开关
|
||||
let volumeLevel = 1.5; // 音量倍率
|
||||
let audioUnlocked = false; // 音频播放是否解锁
|
||||
|
||||
// 解锁音频播放(浏览器需要用户交互后才能自动播放)
|
||||
function unlockAudio() {
|
||||
if (!audioUnlocked) {
|
||||
// 创建一个静音音频来解锁
|
||||
const silentAudio = new Audio();
|
||||
silentAudio.play().then(() => {
|
||||
audioUnlocked = true;
|
||||
console.log('音频播放已解锁');
|
||||
}).catch(e => {
|
||||
console.log('音频解锁失败:', e);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 页面点击解锁音频
|
||||
document.addEventListener('click', unlockAudio, { once: true });
|
||||
document.addEventListener('touchstart', unlockAudio, { once: true });
|
||||
|
||||
// 元素
|
||||
const statusDot = document.getElementById('statusDot');
|
||||
@@ -947,9 +928,6 @@
|
||||
const audio = new Audio(url);
|
||||
const icon = btn.querySelector('.play-icon');
|
||||
|
||||
// 应用音量倍率
|
||||
audio.volume = Math.min(volumeLevel, 2); // 最大不超过2
|
||||
|
||||
audio.onplay = () => {
|
||||
icon.textContent = '🔊';
|
||||
btn.classList.add('playing');
|
||||
@@ -960,21 +938,7 @@
|
||||
btn.classList.remove('playing');
|
||||
};
|
||||
|
||||
audio.onerror = (e) => {
|
||||
console.error('音频播放失败:', url, e);
|
||||
icon.textContent = '❌';
|
||||
btn.classList.remove('playing');
|
||||
};
|
||||
|
||||
// 添加播放失败的catch
|
||||
audio.play().catch(e => {
|
||||
console.error('播放被阻止:', e);
|
||||
icon.textContent = '🔇';
|
||||
// 提示用户点击播放
|
||||
if (e.name === 'NotAllowedError') {
|
||||
showError('请先点击页面解锁音频播放');
|
||||
}
|
||||
});
|
||||
audio.play();
|
||||
}
|
||||
|
||||
// 显示加载
|
||||
|
||||
Reference in New Issue
Block a user