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
870f681d89
commit
5ce7874ffa
@ -5,6 +5,7 @@ use gio::{
|
|||||||
SimpleAction, SimpleActionExt,
|
SimpleAction, SimpleActionExt,
|
||||||
};
|
};
|
||||||
use glib;
|
use glib;
|
||||||
|
use gst_player;
|
||||||
use gtk;
|
use gtk;
|
||||||
use gtk::prelude::*;
|
use gtk::prelude::*;
|
||||||
use gtk::SettingsExt as GtkSettingsExt;
|
use gtk::SettingsExt as GtkSettingsExt;
|
||||||
@ -18,6 +19,7 @@ use stacks::{Content, PopulatedState};
|
|||||||
use utils;
|
use utils;
|
||||||
use widgets::appnotif::{InAppNotification, UndoState};
|
use widgets::appnotif::{InAppNotification, UndoState};
|
||||||
use widgets::player;
|
use widgets::player;
|
||||||
|
use widgets::player::PlayerExt;
|
||||||
use widgets::{about_dialog, mark_all_notif, remove_show_notif};
|
use widgets::{about_dialog, mark_all_notif, remove_show_notif};
|
||||||
|
|
||||||
use std::rc::Rc;
|
use std::rc::Rc;
|
||||||
@ -57,6 +59,7 @@ pub enum Action {
|
|||||||
InitEpisode(i32),
|
InitEpisode(i32),
|
||||||
PlayerDurationChanged(player::Duration),
|
PlayerDurationChanged(player::Duration),
|
||||||
PlayerPositionUpdated(player::Position),
|
PlayerPositionUpdated(player::Position),
|
||||||
|
PlayerEndofStream(gst_player::Player),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -213,6 +216,7 @@ impl App {
|
|||||||
Ok(Action::InitEpisode(rowid)) => player.initialize_episode(rowid).unwrap(),
|
Ok(Action::InitEpisode(rowid)) => player.initialize_episode(rowid).unwrap(),
|
||||||
Ok(Action::PlayerDurationChanged(dur)) => player.timer.on_duration_changed(dur),
|
Ok(Action::PlayerDurationChanged(dur)) => player.timer.on_duration_changed(dur),
|
||||||
Ok(Action::PlayerPositionUpdated(pos)) => player.timer.on_position_updated(pos),
|
Ok(Action::PlayerPositionUpdated(pos)) => player.timer.on_position_updated(pos),
|
||||||
|
Ok(Action::PlayerEndofStream(_)) => player.stop(),
|
||||||
Err(_) => (),
|
Err(_) => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -35,6 +35,7 @@ pub enum SeekDirection {
|
|||||||
pub trait PlayerExt {
|
pub trait PlayerExt {
|
||||||
fn play(&self);
|
fn play(&self);
|
||||||
fn pause(&self);
|
fn pause(&self);
|
||||||
|
fn stop(&self);
|
||||||
fn seek(&self, offset: ClockTime, direction: SeekDirection);
|
fn seek(&self, offset: ClockTime, direction: SeekDirection);
|
||||||
fn fast_forward(&self);
|
fn fast_forward(&self);
|
||||||
fn rewind(&self);
|
fn rewind(&self);
|
||||||
@ -252,6 +253,12 @@ impl PlayerWidget {
|
|||||||
.map_err(|err| error!("Error: {}", err))
|
.map_err(|err| error!("Error: {}", err))
|
||||||
.ok();
|
.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)]
|
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||||
@ -335,6 +342,16 @@ impl PlayerExt for PlayerWidget {
|
|||||||
self.seek(ClockTime::from_seconds(5), SeekDirection::Backwards);
|
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
|
// Adapted from https://github.com/philn/glide/blob/b52a65d99daeab0b487f79a0e1ccfad0cd433e22/src/player_context.rs#L219-L245
|
||||||
fn seek(&self, offset: ClockTime, direction: SeekDirection) {
|
fn seek(&self, offset: ClockTime, direction: SeekDirection) {
|
||||||
let position = self.player.get_position();
|
let position = self.player.get_position();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user