From f7acd8ce9a797620fda011ef3fdbe7ef30b4df08 Mon Sep 17 00:00:00 2001 From: nnwang <10577303+nnwang@user.noreply.gitee.com> Date: Sun, 22 Feb 2026 06:29:50 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0error=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E7=AD=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- play.lua | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/play.lua b/play.lua index c69a3c8..d5636a0 100644 --- a/play.lua +++ b/play.lua @@ -1,8 +1,10 @@ -- 简化版视频播放器 local gpu = peripheral.wrap("tm_gpu_0") +local gpu_Size = 64 + if not gpu then gpu = peripheral.find("tm_gpu") end gpu.refreshSize() -gpu.setSize(64) +gpu.setSize(gpu_Size) local w, h = gpu.getSize() local mypath = "/"..fs.getDir(shell.getRunningProgram()) if not fs.exists(mypath.."/speakerlib.lua") then shell.run("wget https://git.liulikeji.cn/xingluo/computer_craft_video_play/raw/branch/main/speakerlib.lua") end @@ -237,7 +239,7 @@ for _, batch in ipairs(initBatches) do print("[E] " .. batch.start .." "..http_error) if http_error == "Response is too large" then - error("[E] Frame packet size exceeds 16MB. \nPlease try adjusting the screen size or resolution.") + error("\n[E] Frame packet size exceeds 16MB. \nPlease try adjusting the screen size or resolution.") end sleep(0.5) @@ -317,7 +319,7 @@ local function cacheAhead() url = url, headers = { ["Content-Type"] = "application/json" }, body = body, - timeout = 2, + timeout = 3, binary = true }) pendingRequests[url] = batch @@ -352,7 +354,7 @@ local function httpResponseHandler() end local sizeInMB = #binData / (1024 * 1024) - print("[V] Cached batch: " .. batch.start .. " - " .. (batch.start + #batchFrames - 1) .." ("..tonumber(string.format("%.1f", sizeInMB)).."Mb)") + print("[V] Cached batch: " .. batch.start .. " - " .. (batch.start + #batchFrames - 1) .." ("..tonumber(string.format("%.1f", sizeInMB)).." Mb)") else print("[R] Unpack failed for batch " .. batch.start .. ": " .. tostring(batchFrames)) -- 标记这些帧可重试 @@ -385,6 +387,8 @@ local function httpResponseHandler() end end + elseif event == "timer" then + os.queueEvent("time",url, handleOrErr) end end end @@ -400,7 +404,8 @@ local function renderVideo() local fps = videoInfo.fps local frameDelay = 1 / fps local startTime = os.clock() - + local nil_e = 0 + os.queueEvent("audio_start") -- 通知音频开始播放 -- === 性能统计变量 === @@ -443,15 +448,16 @@ local function renderVideo() if debug then -- 格式:帧进度 | 平均FPS(平均耗时) | 最低FPS(波峰耗时) - local statusText = string.format("%d/%d Avg:%d(%dms) Low:%d(%dms)", + local statusText = string.format("%d/%d Avg:%d(%dms) Low:%d(%dms) %dx%d gpuSize:%d", frameIndex, #videoInfo.frame_urls, math.floor(ui_avgFps), math.floor(ui_avgMs), math.floor(ui_lowFps), - math.floor(ui_lowMs) + math.floor(ui_lowMs), + w,h,gpu_Size ) - gpu.drawText(1, 1, statusText, 0xFFFFFF) + gpu.drawText(1, 1, statusText, 0xFD452A) end -- 这里的 Timer 逻辑移出去了,确保跳帧时也能同步 @@ -468,15 +474,20 @@ local function renderVideo() image:free() -- === 修改点:只有成功渲染并同步后,才更新 frameEnd === frameEnd = os.clock() + nil_e = 0 else print("Decode failed frame " .. frameIndex) end else - if frameIndex > 1 and timer_id then - repeat - local event, id = os.pullEvent("timer") - until id == timer_id + print("[E] "..frameIndex.." is nil") + nil_e = nil_e + 1 + if nil_e >= 200 then + error("\n[E] No available video data for 10 seconds \nDownload speed is below the minimum threshold! \nPlease try checking your network bandwidth or adjusting the resolution.") end + repeat + local event, id = os.pullEvent("timer") + until id == timer_id + timer_id = os.startTimer(frameDelay) -- === 修改点:数据为空时,不做任何操作,直接进入下方的同步逻辑 ===