feat: 明确音频优先级,优化发车音频触发时机

- 到达与发车最高优先级(3),其次是进站预告(2),然后是延误警告(1),最低为背景音乐(0)

- 将发车音乐的触发时机从固定时间改为动态计算(音频时长+1.5秒补偿),确保音频结束时列车刚好发车

- 拆分 handleTrainApproaching 与 handleTrainAlert 逻辑,解耦进站与延误的优先级

- 版本号提升至 v1.0.59
This commit is contained in:
2026-08-04 13:00:04 +08:00
parent 01ac488aef
commit d8eee041c8
4 changed files with 150 additions and 43 deletions
+13 -5
View File
@@ -1,6 +1,6 @@
-- 1. Configuration & Constants
local APP_VERSION_TEXT = "v1.0.58"
local APP_VERSION_TEXT = "v1.0.59"
local CONFIG = {
CLOUD_URL = "ws://stabadmin.fse-media.group",
@@ -2161,6 +2161,11 @@ function Network.messageLoop()
local flushBelow = data.flushBelow
Audio.stop(mode, flushBelow)
end
elseif data.type == "train_arrival_ack" then
if State.currentTrain and State.currentTrain.id == data.trainId then
State.currentTrain.departureDuration = tonumber(data.departureDuration) or 10
Utils.log("INFO", "Got departure audio duration: " .. State.currentTrain.departureDuration .. "s")
end
elseif data.type == "station_update" then
local targetVersion = AutoUpdate.getTargetVersion(data)
if targetVersion == "" then
@@ -2752,7 +2757,7 @@ function Main.loop()
State.announcedAlerts[alertKey] = now
Utils.log("INFO", string.format("Train Alert: %s (ETA: %ds, Delay: %dm, Cancelled: %s, Reason: %s)", trainName, etaSeconds, displayDelayMinutes, tostring(cancelled), tostring(reason or "")))
Network.send({
type = "train_approaching",
type = "train_alert",
stationName = State.stationName,
stationCode = State.stationCode,
stationPlatform = platform,
@@ -2908,7 +2913,7 @@ function Main.loop()
State.announcedAlerts[alertKey] = now
Utils.log("INFO", string.format("Train Delay Alert: %s (ETA: %ds, Delay: %dm)", tName, etaSeconds, delay))
Network.send({
type = "train_approaching",
type = "train_alert",
stationName = State.stationName,
stationCode = State.stationCode,
stationPlatform = platform or State.stationPlatform or "1",
@@ -3029,11 +3034,14 @@ function Main.loop()
trainId = id,
destination = dest,
nextStation = nextStation,
departureTime = State.currentTrain.departureTime
departureTime = State.currentTrain.departureTime,
departureBeep = State.departureBeep
})
else
local now = os.epoch("utc") / 1000
if not State.currentTrain.departureSent and (State.currentTrain.departureTime - now) <= 10 then
-- 增加 1.5 秒网络与预缓冲补偿,确保音频结束时列车刚好发车
local triggerOffset = (State.currentTrain.departureDuration or 10) + 1.5
if not State.currentTrain.departureSent and (State.currentTrain.departureTime - now) <= triggerOffset then
State.currentTrain.departureSent = true
Network.send({
type = "train_departure",