Skip to content

Instantly share code, notes, and snippets.

@dividuum
Created September 1, 2015 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dividuum/61c7d18f37ea97132424 to your computer and use it in GitHub Desktop.
Save dividuum/61c7d18f37ea97132424 to your computer and use it in GitHub Desktop.
gl.setup(NATIVE_WIDTH, NATIVE_HEIGHT)
node.alias "looper"
local Looper = function(file)
local vid = resource.load_video(file, false, true)
local function draw()
util.draw_correct(vid, 0, 0, WIDTH, HEIGHT)
return true
end
local function set_running(running)
if running then
vid:start()
else
vid:stop()
end
end
return {
draw = draw;
set_running = set_running;
}
end
local Intermission = function(file)
local vid = resource.create_colored_texture(0, 0, 0, 0)
local function draw()
util.draw_correct(vid, 0, 0, WIDTH, HEIGHT)
return vid:state() ~= "finished"
end
local function preload()
if vid then vid:dispose() end
vid = resource.load_video(file, false, false, true)
end
local function set_running(running)
if running then
vid:start()
else
preload()
end
end
preload()
return {
draw = draw;
set_running = set_running;
}
end
local loop = Looper "loop.mp4"
local intermission = Intermission "intermission.mp4"
local surface
local function start_loop()
loop.set_running(true)
intermission.set_running(false)
surface = loop
end
local function start_intermission()
loop.set_running(false)
intermission.set_running(true)
surface = intermission
end
util.data_mapper{
["set"] = function(new_mode)
if new_mode == "loop" then
start_loop()
else
start_intermission()
end
end;
}
start_loop()
function node.render()
if not surface.draw() then
start_loop()
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment