Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(player): reset library item time offset if selected video don't match state #755

Merged
merged 1 commit into from
Dec 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion src/models/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ impl<E: Env + 'static> UpdateWithCtx<E> for Player {
&self.meta_item,
&ctx.library,
);

let library_item_state_effects =
library_item_state_update(&mut self.library_item, &self.selected);

let watched_effects =
watched_update(&mut self.watched, &self.meta_item, &self.library_item);

Expand Down Expand Up @@ -280,6 +284,7 @@ impl<E: Env + 'static> UpdateWithCtx<E> for Player {
.join(update_streams_effects)
.join(series_info_effects)
.join(library_item_effects)
.join(library_item_state_effects)
.join(watched_effects)
.join(skip_gaps_effects)
.join(intro_outro_update_effects)
Expand Down Expand Up @@ -678,10 +683,15 @@ impl<E: Env + 'static> UpdateWithCtx<E> for Player {
&ctx.library,
);

let library_item_state_effects =
library_item_state_update(&mut self.library_item, &self.selected);

let watched_effects =
watched_update(&mut self.watched, &self.meta_item, &self.library_item);

library_item_effects.join(watched_effects)
library_item_effects
.join(library_item_state_effects)
.join(watched_effects)
}
Msg::Internal(Internal::StreamsChanged(_)) => {
stream_state_update(&mut self.stream_state, &self.selected, &ctx.streams)
Expand Down Expand Up @@ -761,6 +771,10 @@ impl<E: Env + 'static> UpdateWithCtx<E> for Player {
&self.meta_item,
&ctx.library,
);

let library_item_state_effects =
library_item_state_update(&mut self.library_item, &self.selected);

let watched_effects =
watched_update(&mut self.watched, &self.meta_item, &self.library_item);

Expand Down Expand Up @@ -803,6 +817,7 @@ impl<E: Env + 'static> UpdateWithCtx<E> for Player {
.join(next_stream_effects)
.join(series_info_effects)
.join(library_item_effects)
.join(library_item_state_effects)
.join(watched_effects)
.join(skip_gaps_effects)
}
Expand Down Expand Up @@ -1122,6 +1137,28 @@ fn watched_update(
eq_update(watched, next_watched)
}

fn library_item_state_update(
library_item: &mut Option<LibraryItem>,
selected: &Option<Selected>,
) -> Effects {
match (library_item, selected) {
(Some(library_item), Some(selected)) => {
match (&selected.stream_request, &library_item.state.video_id) {
(Some(stream_request), Some(state_video_id))
if stream_request.path.id != *state_video_id =>
{
library_item.state.time_offset = 0;
Effects::msg(Msg::Internal(Internal::UpdateLibraryItem(
library_item.to_owned(),
)))
}
_ => Effects::none().unchanged(),
}
}
_ => Effects::none().unchanged(),
}
}

fn subtitles_update<E: Env + 'static>(
subtitles: &mut Vec<ResourceLoadable<Vec<Subtitles>>>,
selected: &Option<Selected>,
Expand Down
Loading