feat(station-broadcast, cloud-server): 添加HLS播放与循环播放支持,更新脚本拉取地址

调整两个工具脚本的远程拉取地址,将固定commit哈希链接改为main分支链接;为云服务端添加loop参数与HLS音频播放支持,重构音频播放逻辑简化冗余代码;为station_broadcast.lua新增hls格式支持与循环播放控制,完善网络消息参数处理。
This commit is contained in:
2026-07-31 20:42:22 +08:00
parent 3f58d03d15
commit 6d65b8216a
4 changed files with 52 additions and 22 deletions
+23 -5
View File
@@ -718,10 +718,18 @@ local function playHqAudioItem(item)
local controller = Peripherals.speakers[1]
local called = false
local loopEnabled = item.loop and true or false
if controller then
pcall(function()
if type(controller.setLoopingAll) == "function" then
controller.setLoopingAll(loopEnabled)
end
end)
local ok, result = pcall(function()
if format == "wav" and type(controller.speakWavAll) == "function" then
if format == "hls" and type(controller.speakHLSAll) == "function" then
return controller.speakHLSAll(payload, CONFIG.AUDIO_VOLUME)
elseif format == "wav" and type(controller.speakWavAll) == "function" then
return controller.speakWavAll(payload, CONFIG.AUDIO_VOLUME)
elseif format == "mp3" and type(controller.speakMp3All) == "function" then
return controller.speakMp3All(payload, CONFIG.AUDIO_VOLUME)
@@ -738,8 +746,15 @@ local function playHqAudioItem(item)
if not called then
for _, sp in ipairs(Peripherals.speakers) do
pcall(function()
if type(sp.setLooping) == "function" then
sp.setLooping(loopEnabled)
end
end)
local ok, result = pcall(function()
if format == "wav" and type(sp.speakWav) == "function" then
if format == "hls" and type(sp.speakHLS) == "function" then
return sp.speakHLS(payload, CONFIG.AUDIO_VOLUME)
elseif format == "wav" and type(sp.speakWav) == "function" then
return sp.speakWav(payload, CONFIG.AUDIO_VOLUME)
elseif format == "mp3" and type(sp.speakMp3) == "function" then
return sp.speakMp3(payload, CONFIG.AUDIO_VOLUME)
@@ -811,7 +826,7 @@ end
function Audio.playItem(item)
local format = tostring(item.audioFormat or "dfpwm"):lower()
if format == "wav" or format == "file" or format == "stream" then
if format == "wav" or format == "file" or format == "stream" or format == "hls" then
return playHqAudioItem(item)
end
return Audio.playDfpwmItem(item)
@@ -1092,6 +1107,7 @@ function Network.messageLoop()
audioData = table.concat(rx.chunks or {}),
audioFormat = rx.audioFormat or "wav",
priority = rx.priority,
loop = rx.loop and true or false,
source = rx.source,
audioId = rx.audioId
})
@@ -1129,15 +1145,17 @@ function Network.messageLoop()
expectedBytes = tonumber(data.byteLength) or 0,
receivedBytes = 0,
priority = priority,
loop = data.loop and true or false,
source = data.source or data.category,
audioFormat = audioFormat
}
if audioFormat == "stream" and streamUrl and streamUrl ~= "" then
if (audioFormat == "stream" or audioFormat == "hls") and streamUrl and streamUrl ~= "" then
Audio.enqueueItem({
audioData = streamUrl,
audioFormat = "stream",
audioFormat = audioFormat,
priority = priority,
loop = State.audioRx.loop,
source = State.audioRx.source,
audioId = data.audioId
})