Created
September 1, 2015 15:08
-
-
Save dividuum/61c7d18f37ea97132424 to your computer and use it in GitHub Desktop.
Example code for https://www.raspberrypi.org/forums/viewtopic.php?f=38&t=119469
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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