Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/schizobulia/bevy_gst_video
Implement player function in bevy
https://github.com/schizobulia/bevy_gst_video
Last synced: 3 months ago
JSON representation
Implement player function in bevy
- Host: GitHub
- URL: https://github.com/schizobulia/bevy_gst_video
- Owner: schizobulia
- Created: 2024-06-26T09:54:47.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-07-01T12:48:04.000Z (6 months ago)
- Last Synced: 2024-07-05T15:25:22.129Z (6 months ago)
- Language: Rust
- Homepage: https://www.yuque.com/anruofusheng/bytlpr/pu6wezp7cntb1gcf
- Size: 95.7 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## bevy_gst_video
```rust
use std::collections::VecDeque;use bevy::prelude::*;
use plugin::{insert_video_component, VideoPlayer, VideoState};
mod plugin;
mod video;fn main() {
App::new()
.add_plugins((DefaultPlugins, plugin::VideoPlugin))
.add_systems(Startup, start_up)
.add_systems(
Update,
(update, plugin::add_video_frame, plugin::render_video_frame),
)
.run();
}fn start_up(mut commands: Commands, images: ResMut>, asset_server: Res) {
commands.spawn((Camera2dBundle::default(), IsDefaultUiCamera));
let uri = "https://gstreamer.freedesktop.org/data/media/sintel_trailer-480p.webm";
let video_player = VideoPlayer {
uri: uri.to_string(),
state: VideoState::Init,
timer: Timer::from_seconds(0.1, TimerMode::Repeating),
data: VecDeque::new(),
width: 500.0,
height: 500.0,
id: None,
pipeline: None,
};
commands
.spawn(insert_video_component(
images,
Vec2::new(video_player.width, video_player.height),
))
.insert(video_player);commands
.spawn(NodeBundle {
style: Style {
top: Val::Px(550.0),
left: Val::Px(200.0),
..Default::default()
},
..Default::default()
})
.with_children(|parent| {
parent
.spawn(TextBundle::from_section(
"start ",
TextStyle {
font: asset_server.load("fonts/FiraMono-Medium.ttf"),
font_size: 12.0,
color: Color::WHITE,
..Default::default()
},
))
.insert(Interaction::Pressed);
parent
.spawn(TextBundle::from_section(
" stop",
TextStyle {
font: asset_server.load("fonts/FiraMono-Medium.ttf"),
font_size: 12.0,
color: Color::WHITE,
..Default::default()
},
))
.insert(Interaction::Pressed);
});
}fn update(
mut query: Query<(&Interaction, &mut Text)>,
mut query_video: Query<(&mut VideoPlayer, Entity, &mut UiImage)>,
) {
for (mut video_player, id, _) in query_video.iter_mut() {
for (interaction, text) in query.iter_mut() {
match interaction {
Interaction::Pressed => {
if video_player.id.is_some() {
match text.sections[0].value.trim() {
"start" => {
video_player.state = VideoState::Start;
}
"stop" => {
video_player.state = VideoState::Paused;
}
_ => {}
}
}
}
_ => {}
}
}if video_player.id.is_none() {
video_player.id = Some(id);
}
}
}
```