添加error报错等
This commit is contained in:
29
play.lua
29
play.lua
@@ -1,8 +1,10 @@
|
|||||||
-- 简化版视频播放器
|
-- 简化版视频播放器
|
||||||
local gpu = peripheral.wrap("tm_gpu_0")
|
local gpu = peripheral.wrap("tm_gpu_0")
|
||||||
|
local gpu_Size = 64
|
||||||
|
|
||||||
if not gpu then gpu = peripheral.find("tm_gpu") end
|
if not gpu then gpu = peripheral.find("tm_gpu") end
|
||||||
gpu.refreshSize()
|
gpu.refreshSize()
|
||||||
gpu.setSize(64)
|
gpu.setSize(gpu_Size)
|
||||||
local w, h = gpu.getSize()
|
local w, h = gpu.getSize()
|
||||||
local mypath = "/"..fs.getDir(shell.getRunningProgram())
|
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
|
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)
|
print("[E] " .. batch.start .." "..http_error)
|
||||||
|
|
||||||
if http_error == "Response is too large" then
|
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
|
end
|
||||||
|
|
||||||
sleep(0.5)
|
sleep(0.5)
|
||||||
@@ -317,7 +319,7 @@ local function cacheAhead()
|
|||||||
url = url,
|
url = url,
|
||||||
headers = { ["Content-Type"] = "application/json" },
|
headers = { ["Content-Type"] = "application/json" },
|
||||||
body = body,
|
body = body,
|
||||||
timeout = 2,
|
timeout = 3,
|
||||||
binary = true
|
binary = true
|
||||||
})
|
})
|
||||||
pendingRequests[url] = batch
|
pendingRequests[url] = batch
|
||||||
@@ -352,7 +354,7 @@ local function httpResponseHandler()
|
|||||||
end
|
end
|
||||||
local sizeInMB = #binData / (1024 * 1024)
|
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
|
else
|
||||||
print("[R] Unpack failed for batch " .. batch.start .. ": " .. tostring(batchFrames))
|
print("[R] Unpack failed for batch " .. batch.start .. ": " .. tostring(batchFrames))
|
||||||
-- 标记这些帧可重试
|
-- 标记这些帧可重试
|
||||||
@@ -385,6 +387,8 @@ local function httpResponseHandler()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
elseif event == "timer" then
|
||||||
|
os.queueEvent("time",url, handleOrErr)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -400,6 +404,7 @@ local function renderVideo()
|
|||||||
local fps = videoInfo.fps
|
local fps = videoInfo.fps
|
||||||
local frameDelay = 1 / fps
|
local frameDelay = 1 / fps
|
||||||
local startTime = os.clock()
|
local startTime = os.clock()
|
||||||
|
local nil_e = 0
|
||||||
|
|
||||||
os.queueEvent("audio_start") -- 通知音频开始播放
|
os.queueEvent("audio_start") -- 通知音频开始播放
|
||||||
|
|
||||||
@@ -443,15 +448,16 @@ local function renderVideo()
|
|||||||
|
|
||||||
if debug then
|
if debug then
|
||||||
-- 格式:帧进度 | 平均FPS(平均耗时) | 最低FPS(波峰耗时)
|
-- 格式:帧进度 | 平均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,
|
frameIndex,
|
||||||
#videoInfo.frame_urls,
|
#videoInfo.frame_urls,
|
||||||
math.floor(ui_avgFps),
|
math.floor(ui_avgFps),
|
||||||
math.floor(ui_avgMs),
|
math.floor(ui_avgMs),
|
||||||
math.floor(ui_lowFps),
|
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
|
end
|
||||||
|
|
||||||
-- 这里的 Timer 逻辑移出去了,确保跳帧时也能同步
|
-- 这里的 Timer 逻辑移出去了,确保跳帧时也能同步
|
||||||
@@ -468,15 +474,20 @@ local function renderVideo()
|
|||||||
image:free()
|
image:free()
|
||||||
-- === 修改点:只有成功渲染并同步后,才更新 frameEnd ===
|
-- === 修改点:只有成功渲染并同步后,才更新 frameEnd ===
|
||||||
frameEnd = os.clock()
|
frameEnd = os.clock()
|
||||||
|
nil_e = 0
|
||||||
else
|
else
|
||||||
print("Decode failed frame " .. frameIndex)
|
print("Decode failed frame " .. frameIndex)
|
||||||
end
|
end
|
||||||
else
|
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
|
repeat
|
||||||
local event, id = os.pullEvent("timer")
|
local event, id = os.pullEvent("timer")
|
||||||
until id == timer_id
|
until id == timer_id
|
||||||
end
|
|
||||||
|
|
||||||
timer_id = os.startTimer(frameDelay)
|
timer_id = os.startTimer(frameDelay)
|
||||||
-- === 修改点:数据为空时,不做任何操作,直接进入下方的同步逻辑 ===
|
-- === 修改点:数据为空时,不做任何操作,直接进入下方的同步逻辑 ===
|
||||||
|
|||||||
Reference in New Issue
Block a user