添加error报错等
This commit is contained in:
27
play.lua
27
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
|
||||
@@ -385,6 +387,8 @@ local function httpResponseHandler()
|
||||
end
|
||||
end
|
||||
|
||||
elseif event == "timer" then
|
||||
os.queueEvent("time",url, handleOrErr)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -400,6 +404,7 @@ 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
|
||||
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
|
||||
end
|
||||
|
||||
|
||||
timer_id = os.startTimer(frameDelay)
|
||||
-- === 修改点:数据为空时,不做任何操作,直接进入下方的同步逻辑 ===
|
||||
|
||||
Reference in New Issue
Block a user