-- 简化版视频播放器 local gpu = peripheral.wrap("tm_gpu_0") local gpu_Size_Auto = true --自动分辨率设置 local gpu_Size = 64 --默认屏幕分辨率 if not gpu then gpu = peripheral.find("tm_gpu") end gpu.refreshSize() gpu.setSize(gpu_Size) local w, h, w_black, h_black, Size = gpu.getSize() -- 分批下载(每批 10 帧) local BATCH_SIZE = 10 local function computeOptimalSize(w_black, h_black) local w_target, h_target = 640, 360 local max_size = 64 -- 避免除零 if w_black <= 0 or h_black <= 0 then return 1 end -- 计算理想缩放比例(不能让任一边超过目标) local size_by_w = w_target / w_black local size_by_h = h_target / h_black local ideal_size = math.min(size_by_w, size_by_h) -- 如果理想值 >= 64,直接用 64 if ideal_size >= max_size then return max_size end -- 否则,在 floor 和 ceil 中选更优的(但不能超过 64) local size_floor = math.floor(ideal_size) local size_ceil = math.ceil(ideal_size) -- 确保不越界 if size_floor < 1 then size_floor = 1 end if size_ceil > max_size then size_ceil = max_size end -- 计算两个候选的误差(欧氏距离或曼哈顿距离均可,这里用平方和) local function error(size) local w = w_black * size local h = h_black * size return (w - w_target)^2 + (h - h_target)^2 end local err_floor = error(size_floor) local err_ceil = error(size_ceil) if err_floor <= err_ceil then return size_floor else return size_ceil end end if gpu_Size_Auto then local optimal_Size = computeOptimalSize(w_black, h_black) print("[I] gpu_Size: "..optimal_Size) gpu.refreshSize() gpu.setSize(optimal_Size) end local w, h, w_black, h_black, Size = 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 local server_url = "https://newgmapi.liulikeji.cn" -- 检查命令行参数 local age = {...} local videoUrl = age[1] local debug if age[2] == "debug" then debug = true end if not videoUrl then print("Usage: video_player