Skip to main content

freya_video/
lib.rs

1//! Video playback for Freya, backed by ffmpeg and rodio.
2//!
3//! - [`use_video`]: a hook that decodes a video into reactive state and returns a
4//!   [`VideoPlayer`] to control playback.
5//!
6//! Render the current frame yourself with the `image()` element from `player.frame()`.
7//!
8//! Call [`ensure_ffmpeg`] once before `launch()` to auto-download an ffmpeg binary.
9//!
10//! This crate is reexported in `freya::video`.
11//!
12//! # Example
13//!
14//! ```rust, no_run
15//! use freya::{
16//!     elements::image::image,
17//!     prelude::*,
18//!     video::*,
19//! };
20//!
21//! fn app() -> impl IntoElement {
22//!     let player = use_video(|| "video.mp4");
23//!
24//!     rect().maybe_child(player.frame().map(image))
25//! }
26//! ```
27
28mod client;
29mod player;
30
31pub use self::{
32    client::{
33        VideoClient,
34        VideoEvent,
35        VideoSource,
36    },
37    player::{
38        PlaybackState,
39        VideoPlayer,
40        use_video,
41    },
42};
43
44/// Download an ffmpeg binary if one isn't already available on `PATH`.
45/// Call from `main` before `launch()` to opt in to auto-install.
46pub fn ensure_ffmpeg() -> anyhow::Result<()> {
47    ffmpeg_sidecar::download::auto_download()
48}