PlayerExt: Add a stop method.
Also connect on the gst_player::Player::connect_on_stream_end method. The main reason for this is to be able to reset the slider bar to 0 upon a stream ends.
This commit is contained in:
parent
a83270699f
commit
3e2ab8e7ee
@ -5,6 +5,7 @@ use gio::{
|
||||
SimpleAction, SimpleActionExt,
|
||||
};
|
||||
use glib;
|
||||
use gst_player;
|
||||
use gtk;
|
||||
use gtk::prelude::*;
|
||||
use gtk::SettingsExt as GtkSettingsExt;
|
||||
@ -18,6 +19,7 @@ use stacks::{Content, PopulatedState};
|
||||
use utils;
|
||||
use widgets::appnotif::{InAppNotification, UndoState};
|
||||
use widgets::player;
|
||||
use widgets::player::PlayerExt;
|
||||
use widgets::{about_dialog, mark_all_notif, remove_show_notif};
|
||||
|
||||
use std::rc::Rc;
|
||||
@ -57,6 +59,7 @@ pub enum Action {
|
||||
InitEpisode(i32),
|
||||
PlayerDurationChanged(player::Duration),
|
||||
PlayerPositionUpdated(player::Position),
|
||||
PlayerEndofStream(gst_player::Player),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
@ -213,6 +216,7 @@ impl App {
|
||||
Ok(Action::InitEpisode(rowid)) => player.initialize_episode(rowid).unwrap(),
|
||||
Ok(Action::PlayerDurationChanged(dur)) => player.timer.on_duration_changed(dur),
|
||||
Ok(Action::PlayerPositionUpdated(pos)) => player.timer.on_position_updated(pos),
|
||||
Ok(Action::PlayerEndofStream(_)) => player.stop(),
|
||||
Err(_) => (),
|
||||
}
|
||||
|
||||
|
||||
@ -35,6 +35,7 @@ pub enum SeekDirection {
|
||||
pub trait PlayerExt {
|
||||
fn play(&self);
|
||||
fn pause(&self);
|
||||
fn stop(&self);
|
||||
fn seek(&self, offset: ClockTime, direction: SeekDirection);
|
||||
fn fast_forward(&self);
|
||||
fn rewind(&self);
|
||||
@ -252,6 +253,12 @@ impl PlayerWidget {
|
||||
.map_err(|err| error!("Error: {}", err))
|
||||
.ok();
|
||||
}));
|
||||
|
||||
s.player.connect_end_of_stream(clone!(sender => move |player| {
|
||||
sender.send(Action::PlayerEndofStream(player.clone()))
|
||||
.map_err(|err| error!("Error: {}", err))
|
||||
.ok();
|
||||
}));
|
||||
}
|
||||
|
||||
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||
@ -335,6 +342,16 @@ impl PlayerExt for PlayerWidget {
|
||||
self.seek(ClockTime::from_seconds(5), SeekDirection::Backwards);
|
||||
}
|
||||
|
||||
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||
fn stop(&self) {
|
||||
self.controls.pause.hide();
|
||||
self.controls.play.show();
|
||||
|
||||
self.player.stop();
|
||||
|
||||
self.timer.on_position_updated(Position(ClockTime::from_seconds(0)));
|
||||
}
|
||||
|
||||
// Adapted from https://github.com/philn/glide/blob/b52a65d99daeab0b487f79a0e1ccfad0cd433e22/src/player_context.rs#L219-L245
|
||||
fn seek(&self, offset: ClockTime, direction: SeekDirection) {
|
||||
let position = self.player.get_position();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user