From 330bfa8f806d24459e92799d0a40a2f656116ee1 Mon Sep 17 00:00:00 2001 From: hkc Date: Sun, 15 Sep 2024 03:08:14 +0300 Subject: [PATCH] Added "-wait" parameter --- video.lua | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/video.lua b/video.lua index 539bc4e..ada1ef8 100644 --- a/video.lua +++ b/video.lua @@ -11,6 +11,7 @@ local speakers = { local delay = 0 local loading_concurrency = 8 local buffer_size = 8192 +local wait_until_input = false while args[1] ~= nil and string.sub(args[1], 1, 1) == "-" do local k = table.remove(args, 1):sub(2) @@ -26,6 +27,8 @@ while args[1] ~= nil and string.sub(args[1], 1, 1) == "-" do loading_concurrency = tonumber(table.remove(args, 1)) elseif k == "b" or k == "buffer-size" then buffer_size = tonumber(table.remove(args, 1)) + elseif k == "w" or k == "wait" then + wait_until_input = true end end @@ -46,7 +49,7 @@ end print(string.format("Using monitor %s", peripheral.getName(monitor))) if speakers.r then - print("Stereo sound: L=%s R=%s", peripheral.getName(speakers.l), peripheral.getName(speakers.r)) + print(string.format("Stereo sound: L=%s R=%s", peripheral.getName(speakers.l), peripheral.getName(speakers.r))) else print("Mono sound: " .. peripheral.getName(speakers.l)) end @@ -158,11 +161,19 @@ local playback_locked = true local playback_done = false table.insert(subthreads, function() - while #frames < 60 or #audio_frames.l < n_audio_samples do + local tmr = os.startTimer(0.25) + while true do + local ev = { os.pullEvent() } + if ev[1] == "key" and ev[2] == keys.enter then + break + end term.setCursorPos(1, ty - 1) term.setBackgroundColor(colors.gray) term.clearLine() - term.write(string.format("Waiting for frames... (V:%d, A:%d)", #frames, #audio_frames.l)) + term.write(string.format("Waiting for frames... (V:%d, A:%d) [ENTER to skip]", #frames, #audio_frames.l)) + if #frames < 60 and #audio_frames.l < n_audio_samples and not wait_until_input then + break + end os.sleep(0.25) end playback_locked = false @@ -210,10 +221,12 @@ table.insert(subthreads, function() while not playback_done do local frame = math.floor((os.clock() - start_t) / math.max(0.05, delay)) term.setCursorPos(1, ty - 1) - term.setBackgroundColor(colors.gray) + term.setBackgroundColor(frame >= #frames and colors.red or colors.gray) term.clearLine() term.write(string.format("Playing frame: %d/%d", frame + 1, #frames)) - ccpi.draw(frames[frame + 1], 1, 1, monitor) + if frames[frame] then + ccpi.draw(frames[frame + 1], 1, 1, monitor) + end os.sleep(delay) end end)