fix(audio): 修复导致完全没有声音的回归错误,添加超时防止挂起,修复等待缓冲区清空的逻辑
This commit is contained in:
@@ -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() }
|
||||
|
||||
Reference in New Issue
Block a user