| Crates.io | gpui-video-player |
| lib.rs | gpui-video-player |
| version | 0.1.2 |
| created_at | 2025-10-10 13:15:08.630861+00 |
| updated_at | 2025-11-19 16:06:15.348431+00 |
| description | A video player library for gpui applications, built on top of GStreamer. |
| homepage | https://github.com/cijiugechu/gpui-video-player |
| repository | https://github.com/cijiugechu/gpui-video-player |
| max_upload_size | |
| id | 1876917 |
| size | 281,796 |
gpui-video-playerA video player library for gpui applications, built on top of GStreamer. This library provides efficient video playback with hardware-accelerated rendering on supported platforms.

This library requires GStreamer and its plugins to be installed on your system. Please refer to the GStreamer Rust bindings installation guide for detailed instructions.
Minimum Requirements:
Add this to your Cargo.toml:
[dependencies]
gpui-video-player = "0.1.0"
Note: This library depends on GPUI, which must be available in your project. The current version requires GPUI from the Zed repository.
use gpui::{App, Application, Context, Render, Window, WindowOptions, div, prelude::*};
use gpui_video_player::{Video, video};
use std::path::PathBuf;
use url::Url;
struct VideoPlayer {
video: Video,
}
impl Render for VideoPlayer {
fn render(&mut self, _window: &mut Window, _cx: &mut Context<Self>) -> impl IntoElement {
div()
.size_full()
.flex()
.items_center()
.justify_center()
.child(
video(self.video.clone())
.id("main-video")
.buffer_capacity(30), // Buffer up to 30 frames
)
}
}
fn main() {
env_logger::init();
Application::new().run(|cx: &mut App| {
let uri = Url::from_file_path(
PathBuf::from("./path/to/your/video.mp4"),
).expect("invalid file path");
cx.open_window(
WindowOptions {
focus: true,
..Default::default()
},
|_, cx| {
let video = Video::new(&uri).expect("failed to create video");
cx.new(|_| VideoPlayer { video })
},
).unwrap();
cx.activate(true);
});
}
use gpui_video_player::Video;
use std::time::Duration;
// Playback control
video.set_paused(true); // Pause
video.set_paused(false); // Resume
// Seeking
video.seek(Duration::from_secs(30), false)?; // Seek to 30 seconds
// Volume control
video.set_volume(0.5); // 50% volume
video.set_muted(true); // Mute
// Speed control
video.set_speed(2.0)?; // 2x speed
// Display size
video.set_display_width(Some(800)); // Override width
video.set_display_height(Some(600)); // Override height
use gpui_video_player::{Video, VideoOptions, video};
let options = VideoOptions {
frame_buffer_capacity: Some(10), // Buffer 10 frames
looping: Some(true), // Enable looping
speed: Some(1.5), // 1.5x speed
};
let video = Video::new_with_options(&uri, options)?;
use gpui_video_player::{Video, VideoOptions};
let looped_video = Video::new_with_options(
&uri,
VideoOptions {
looping: Some(true),
..VideoOptions::default()
},
)?;
looped_video.set_looping(true);
Call set_looping(true) at runtime whenever you want to ensure the current stream loops.
use gpui_video_player::{VideoElement, video};
let video_element = video(my_video)
.id("custom-video")
.size(px(640.0), px(480.0)) // Set display size
.buffer_capacity(5); // Buffer 5 frames
The main video player struct with methods for:
set_paused(), paused()seek(), position(), duration()set_volume(), volume(), set_muted(), muted()set_speed(), speed()display_size(), set_display_size()current_frame_data(), take_frame_ready()GPUI element for rendering video with:
size(), width(), height()buffer_capacity()id()Time or frame-based positioning:
use gpui_video_player::Position;
use std::time::Duration;
let time_pos = Position::Time(Duration::from_secs(10));
let frame_pos = Position::Frame(300);
Run the included examples to see the library in action:
# Basic video player
cargo run --example video_player
# Video player with controls
cargo run --example with_controls
# Looping playback
cargo run --example looping
CVPixelBuffer for hardware-accelerated rendering when possibleUses optimized software rendering via GPUI sprite atlas
Supports various GStreamer backends
Contributions are welcome! Please feel free to submit issues and pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.
This project is inspired by and has referenced code from iced_video_player by @jazzfool.