优化
This commit is contained in:
@@ -4,6 +4,7 @@ export const AUDIO_FEEDBACK_SOURCES = Object.freeze({
|
||||
})
|
||||
|
||||
let audioContext = null
|
||||
let hasStartedPlayback = false
|
||||
|
||||
function getAudioContext() {
|
||||
if (audioContext) return audioContext
|
||||
@@ -22,9 +23,10 @@ export function playFeedbackSound(type) {
|
||||
if (!source || !player) return false
|
||||
|
||||
try {
|
||||
player.stop()
|
||||
if (hasStartedPlayback) player.stop()
|
||||
player.src = source
|
||||
player.play()
|
||||
hasStartedPlayback = true
|
||||
return true
|
||||
} catch (_) {
|
||||
return false
|
||||
@@ -48,4 +50,5 @@ export function destroyFeedbackSound() {
|
||||
if (!audioContext) return
|
||||
try { audioContext.destroy() } catch (_) {}
|
||||
audioContext = null
|
||||
hasStartedPlayback = false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user