更新 play.lua

This commit is contained in:
2026-01-10 02:18:57 +08:00
parent 8a456f3253
commit 6c965525e4

View File

@@ -168,7 +168,7 @@ end
-- 分批下载(每批 50 帧) -- 分批下载(每批 50 帧)
local BATCH_SIZE = 20 local BATCH_SIZE = 20
-- local totalFrames = #videoInfo.frame_urls -- local totalFrames = #videoInfo.frame_urls
local totalFrames = videoInfo.fps * 10 -- 仅下载前10秒以节省时间 local totalFrames = videoInfo.fps * 5 -- 仅下载前5秒以节省时间
local allFrameData = {} local allFrameData = {}
for startIdx = 1, totalFrames, BATCH_SIZE do for startIdx = 1, totalFrames, BATCH_SIZE do
@@ -256,7 +256,7 @@ sleep(1)
-- 播放前已缓存 10 秒 -- 播放前已缓存 10 秒
local totalFramesToPlay = #videoInfo.frame_urls local totalFramesToPlay = #videoInfo.frame_urls
local maxCachedFrames = math.min(videoInfo.fps * 20, totalFramesToPlay) -- 最多缓存 20 秒 local maxCachedFrames = math.min(videoInfo.fps * 20, totalFramesToPlay) -- 最多缓存 20 秒
local nextDownloadIndex = math.min(videoInfo.fps * 10 + 1, totalFramesToPlay + 1) -- 从第 10 秒后开始继续下载 local nextDownloadIndex = math.min(videoInfo.fps * 5 + 1, totalFramesToPlay + 1) -- 从第 5 秒后开始继续下载
-- 标志:是否还在播放 -- 标志:是否还在播放
local running = true local running = true
@@ -360,14 +360,14 @@ local function cacheAhead()
end end
end end
-- 音频播放协程(保持原样) -- -- 音频播放协程(保持原样)
local function playAudio() -- local function playAudio()
os.queueEvent("audio_start") -- 触发同步 -- os.queueEvent("audio_start") -- 触发同步
shell.run("bg speakerlib play " .. -- shell.run("bg speakerlib play " ..
server_url .. videoInfo.audio_dfpwm_url .. " " .. -- server_url .. videoInfo.audio_dfpwm_url .. " " ..
server_url .. videoInfo.audio_dfpwm_left_url .. " " .. -- server_url .. videoInfo.audio_dfpwm_left_url .. " " ..
server_url .. videoInfo.audio_dfpwm_right_url) -- server_url .. videoInfo.audio_dfpwm_right_url)
end -- end
-- 视频渲染协程(稍作优化:及时清理旧帧) -- 视频渲染协程(稍作优化:及时清理旧帧)
local function renderVideo() local function renderVideo()
@@ -455,7 +455,7 @@ end
-- 启动三个协程 -- 启动三个协程
parallel.waitForAll(renderVideo, playAudio, cacheAhead) parallel.waitForAll(renderVideo, cacheAhead)
local endtime = os.clock() local endtime = os.clock()
local time = endtime-starttime1 local time = endtime-starttime1