changing how each slide in the song_editor gets its video background

This commit is contained in:
Chris Cochrun 2025-03-16 22:49:42 -05:00
parent 6fa08c1fec
commit 53791162b1
4 changed files with 49 additions and 13 deletions

2
Cargo.lock generated
View file

@ -3431,7 +3431,7 @@ dependencies = [
[[package]]
name = "iced_video_player"
version = "0.6.0"
source = "git+https://github.com/jackpot51/iced_video_player?branch=cosmic#ff37a34f99814597db0e265e172dd5a85a03394a"
source = "git+https://github.com/jackpot51/iced_video_player.git?branch=cosmic#ff37a34f99814597db0e265e172dd5a85a03394a"
dependencies = [
"glib",
"gstreamer",

View file

@ -16,7 +16,6 @@ serde = { version = "1.0.213", features = ["derive"] }
serde-lexpr = "0.1.3"
tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["fmt", "std", "chrono", "time", "local-time", "env-filter"] }
iced_video_player = { git = "https://github.com/jackpot51/iced_video_player", branch = "cosmic", features = ["wgpu"] }
strum = "0.26.3"
strum_macros = "0.26.4"
ron = "0.8.1"
@ -31,3 +30,13 @@ cosmic-time = "0.2.0"
url = "2"
# rfd = { version = "0.12.1", features = ["xdg-portal"], default-features = false }
[dependencies.iced_video_player]
git = "https://github.com/jackpot51/iced_video_player.git"
branch = "cosmic"
features = ["wgpu"]
[profile.dev]
opt-level = 0
[profile.release]
opt-level = 3

View file

@ -52,6 +52,20 @@ pub struct Background {
pub kind: BackgroundKind,
}
impl TryFrom<&Background> for Video {
type Error = ParseError;
fn try_from(
value: &Background,
) -> std::result::Result<Self, Self::Error> {
Video::new(
&url::Url::from_file_path(value.path.clone())
.map_err(|_| ParseError::BackgroundNotVideo)?,
)
.map_err(|_| ParseError::BackgroundNotVideo)
}
}
impl TryFrom<Background> for Video {
type Error = ParseError;

View file

@ -185,6 +185,7 @@ impl SongEditor {
self.lyrics =
text_editor::Content::with_text(&lyrics)
};
self.background_video(&song.background);
self.background = song.background;
}
Message::ChangeFont(font) => {
@ -260,15 +261,8 @@ impl SongEditor {
if let Some(mut song) = self.song.clone() {
let background =
Background::try_from(path.clone()).ok();
if let Some(background) = background {
if background.kind == BackgroundKind::Video {
let video =
Video::try_from(background).ok();
debug!(?video);
self.video = video;
}
}
song.background = path.try_into().ok();
self.background_video(&background);
song.background = background;
return self.update_song(song);
}
}
@ -309,11 +303,16 @@ impl SongEditor {
if let Ok(slides) = song.to_slides() {
let slides = slides
.into_iter()
.map(|slide| {
.enumerate()
.map(|(index, slide)| {
container(
slide_view(
slide,
&self.video,
if index == 0 {
&self.video
} else {
&None
},
self.current_font,
false,
false,
@ -424,6 +423,20 @@ order",
self.song = Some(song.clone());
Action::UpdateSong(song)
}
fn background_video(&mut self, background: &Option<Background>) {
if let Some(background) = background {
if background.kind == BackgroundKind::Video {
let video =
Video::try_from(background).ok().map(|mut v| {
v.set_looping(true);
v
});
debug!(?video);
self.video = video;
}
}
}
}
impl Default for SongEditor {