#![no_std]
extern crate alloc;
#[macro_use]
extern crate playdate as pd;
use core::ffi::*;
use core::ptr::NonNull;
use pd::ext::PlaydateAPIExt;
use pd::sys::EventLoopCtrl;
use pd::sys::ffi::PlaydateAPI;
use pd::graphics::video::VideoPlayer;
use pd::system::prelude::*;
use pd::graphics::*;
use pd::fs::Path;
const VIDEO_PATH: &Path = "examples/video.pdv";
struct State {
player: VideoPlayer<video::api::Cache, true>,
current: c_int,
length: c_int,
}
#[no_mangle]
fn event_handler(api: NonNull<PlaydateAPI>, event: SystemEvent, _sim_key_code: u32) -> EventLoopCtrl {
if !matches!(event, SystemEvent::Init) {
return EventLoopCtrl::Continue;
}
api.display().set_refresh_rate(20.0);
let player = api.graphics().video().load(VIDEO_PATH).unwrap();
player.use_screen_context();
let system = api.system();
system.set_update_callback_boxed(
move |state| {
state.player.render_frame(state.current).unwrap();
state.current += 1;
if state.current >= state.length {
state.current = 0;
}
system.draw_fps(0, 0);
UpdateCtrl::Continue
},
State { length: player.info().frame_count,
current: 0,
player, },
);
EventLoopCtrl::Continue
}
ll_symbols!();