diff --git a/station_broadcast.lua b/station_broadcast.lua index 6d82f80..8c7fc2f 100644 --- a/station_broadcast.lua +++ b/station_broadcast.lua @@ -2,7 +2,7 @@ -- ============================================================================ -- 1. Configuration & Constants -- ============================================================================ -local APP_VERSION_TEXT = "v1.0.2" +local APP_VERSION_TEXT = "v1.0.3" local CONFIG = { CLOUD_URL = "ws://stabadmin.fse-media.group", @@ -593,35 +593,26 @@ end local function playChunkOnSpeakers(samples, volume, playSeq) if not Peripherals.speakers or #Peripherals.speakers == 0 then return false end - local controller = Peripherals.speakers[1] - if controller and type(controller.playAudioAll) == "function" then - while true do - if shouldStop(playSeq) then return false end - local ok = false - pcall(function() - ok = controller.playAudioAll(samples, volume) - end) - if ok then break end - local ev = { os.pullEvent() } - if ev[1] == "audio_interrupt" and tonumber(ev[2]) and tonumber(ev[2]) >= playSeq then - return false - end - end - else local pending = {} for _, sp in ipairs(Peripherals.speakers) do local name = peripheral.getName(sp) if name then pending[name] = sp end end + local usedNativePath = false while next(pending) do if shouldStop(playSeq) then return false end for name, sp in pairs(pending) do local ok = false pcall(function() - ok = sp.playAudio(samples, volume) + if type(sp.playAudio) == "function" then + ok = sp.playAudio(samples, volume) + end end) - if ok then pending[name] = nil end + if ok then + usedNativePath = true + pending[name] = nil + end end if next(pending) then local ev = { os.pullEvent() } @@ -630,6 +621,28 @@ local function playChunkOnSpeakers(samples, volume, playSeq) end end end + + if usedNativePath then + Utils.log("INFO", string.format("Audio samples queued via native speaker.playAudio: samples=%d", #samples)) + else + local controller = Peripherals.speakers[1] + if controller and type(controller.playAudioAll) == "function" then + Utils.log("WARN", "Falling back to controller.playAudioAll for decoded samples") + while true do + if shouldStop(playSeq) then return false end + local ok = false + pcall(function() + ok = controller.playAudioAll(samples, volume) + end) + if ok then break end + local ev = { os.pullEvent() } + if ev[1] == "audio_interrupt" and tonumber(ev[2]) and tonumber(ev[2]) >= playSeq then + return false + end + end + else + return false + end end local waiting = {}