fix(audio): 修复导致完全没有声音的回归错误,添加超时防止挂起,修复等待缓冲区清空的逻辑

This commit is contained in:
2026-08-16 11:58:31 +08:00
parent af00d57e68
commit 1d99634957
2 changed files with 26 additions and 4 deletions
+5
View File
@@ -61,6 +61,7 @@ local function playDfpwmFile(path, volume)
for _, sp in ipairs(speakers) do
pending[peripheral.getName(sp)] = sp
end
local maxAttempts = 20
while next(pending) do
for name, sp in pairs(pending) do
if sp.playAudio(samples, volume) then
@@ -68,6 +69,10 @@ local function playDfpwmFile(path, volume)
end
end
if next(pending) then
maxAttempts = maxAttempts - 1
if maxAttempts <= 0 then
break
end
local timerId = os.startTimer(0.05)
while true do
local ev = { os.pullEvent() }