Add seek forwards/backwards

This commit is contained in:
Jeremy Soller 2024-01-24 21:06:07 -07:00
parent 48ba7e7278
commit d39c10b946
No known key found for this signature in database
GPG key ID: DCFCA852D3906975
3 changed files with 73 additions and 19 deletions

View file

@ -19,20 +19,21 @@ use std::{
env,
path::PathBuf,
process,
sync::{Arc, Mutex},
sync::{mpsc, Arc, Mutex},
time::Instant,
};
use config::{AppTheme, Config, CONFIG_VERSION};
mod config;
mod ffmpeg;
use key_bind::{key_binds, KeyBind};
mod key_bind;
mod localize;
use player::{PlayerMessage, VideoFrame};
mod player;
/// Runs application with these settings
#[rustfmt::skip]
fn main() -> Result<(), Box<dyn std::error::Error>> {
@ -66,7 +67,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
}
};
let video_frame_lock = ffmpeg::run(path);
let (player_tx, video_frame_lock) = player::run(path);
let mut settings = Settings::default();
settings = settings.theme(config.app_theme.theme());
@ -83,7 +84,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let flags = Flags {
config_handler,
config,
video_frame_lock
player_tx,
video_frame_lock,
};
cosmic::app::run::<App>(settings, flags)?;
@ -93,12 +95,16 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Action {
Todo,
SeekBackward,
SeekForward,
}
impl Action {
pub fn message(&self) -> Message {
match self {
Self::Todo => Message::Todo,
Self::SeekBackward => Message::Player(PlayerMessage::SeekRelative(-10.0)),
Self::SeekForward => Message::Player(PlayerMessage::SeekRelative(10.0)),
}
}
}
@ -107,7 +113,8 @@ impl Action {
pub struct Flags {
config_handler: Option<cosmic_config::Config>,
config: Config,
video_frame_lock: Arc<Mutex<Option<ffmpeg::VideoFrame>>>,
player_tx: mpsc::Sender<PlayerMessage>,
video_frame_lock: Arc<Mutex<Option<VideoFrame>>>,
}
/// Messages that are used specifically by our [`App`].
@ -117,6 +124,7 @@ pub enum Message {
AppTheme(AppTheme),
Config(Config),
Key(Modifiers, KeyCode),
Player(PlayerMessage),
SystemThemeModeChange(cosmic_theme::ThemeMode),
Tick(Instant),
ToggleContextPage(ContextPage),
@ -281,6 +289,9 @@ impl Application for App {
}
}
}
Message::Player(player_message) => {
self.flags.player_tx.send(player_message).unwrap();
}
Message::SystemThemeModeChange(_theme_mode) => {
return self.update_config();
}