PlayerWidget: Add a widget to change the playback speed of the stream.
Only 3 options are offered currently since the design of the feature is still in progress and this is only a throw a away prototype.
This commit is contained in:
parent
593d66ea54
commit
ff2f43766e
@ -250,9 +250,122 @@
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">3</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkMenuButton" id="rate_button">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="margin_left">6</property>
|
||||
<property name="direction">up</property>
|
||||
<property name="popover">rate_popover</property>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="spacing">6</property>
|
||||
<child>
|
||||
<object class="GtkLabel" id="rate_label">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="label" translatable="yes">1.00x</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkImage">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="icon_name">go-down-symbolic</property>
|
||||
<property name="icon_size">1</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="position">4</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
<object class="GtkPopover" id="rate_popover">
|
||||
<property name="can_focus">False</property>
|
||||
<property name="relative_to">rate_button</property>
|
||||
<child>
|
||||
<object class="GtkButtonBox">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">False</property>
|
||||
<property name="orientation">vertical</property>
|
||||
<property name="spacing">3</property>
|
||||
<property name="layout_style">start</property>
|
||||
<child>
|
||||
<object class="GtkRadioButton" id="rate_1_50">
|
||||
<property name="label" translatable="yes">1.50x</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="active">True</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
<property name="group">normal_rate</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkRadioButton" id="rate_1_25">
|
||||
<property name="label" translatable="yes">1.25x</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="active">True</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
<property name="group">normal_rate</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkRadioButton" id="normal_rate">
|
||||
<property name="label" translatable="yes">1.00x</property>
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">False</property>
|
||||
<property name="halign">center</property>
|
||||
<property name="valign">center</property>
|
||||
<property name="active">True</property>
|
||||
<property name="draw_indicator">True</property>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">True</property>
|
||||
<property name="fill">True</property>
|
||||
<property name="position">2</property>
|
||||
</packing>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
||||
|
||||
@ -35,8 +35,7 @@ pub trait PlayerExt {
|
||||
fn seek(&self, offset: ClockTime, direction: SeekDirection);
|
||||
fn fast_forward(&self);
|
||||
fn rewind(&self);
|
||||
// TODO: change playback rate
|
||||
// fn set_playback_rate(&self);
|
||||
fn set_playback_rate(&self, f64);
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
@ -136,6 +135,16 @@ fn format_duration(seconds: u32) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct PlayerRate {
|
||||
radio150: gtk::RadioButton,
|
||||
radio125: gtk::RadioButton,
|
||||
radio_normal: gtk::RadioButton,
|
||||
popover: gtk::Popover,
|
||||
btn: gtk::MenuButton,
|
||||
label: gtk::Label,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
struct PlayerControls {
|
||||
container: gtk::Box,
|
||||
@ -152,6 +161,7 @@ pub struct PlayerWidget {
|
||||
controls: PlayerControls,
|
||||
pub timer: PlayerTimes,
|
||||
info: PlayerInfo,
|
||||
rate: PlayerRate,
|
||||
}
|
||||
|
||||
impl Default for PlayerWidget {
|
||||
@ -207,12 +217,28 @@ impl Default for PlayerWidget {
|
||||
cover,
|
||||
};
|
||||
|
||||
let radio150 = builder.get_object("rate_1_50").unwrap();
|
||||
let radio125 = builder.get_object("rate_1_25").unwrap();
|
||||
let radio_normal = builder.get_object("normal_rate").unwrap();
|
||||
let popover = builder.get_object("rate_popover").unwrap();
|
||||
let btn = builder.get_object("rate_button").unwrap();
|
||||
let label = builder.get_object("rate_label").unwrap();
|
||||
let rate = PlayerRate {
|
||||
radio150,
|
||||
radio125,
|
||||
radio_normal,
|
||||
popover,
|
||||
label,
|
||||
btn,
|
||||
};
|
||||
|
||||
PlayerWidget {
|
||||
player,
|
||||
action_bar,
|
||||
controls,
|
||||
timer,
|
||||
info,
|
||||
rate,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -226,7 +252,8 @@ impl PlayerWidget {
|
||||
|
||||
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||
fn init(s: &Rc<Self>, sender: &Sender<Action>) {
|
||||
Self::connect_buttons(s);
|
||||
Self::connect_control_buttons(s);
|
||||
Self::connect_rate_buttons(s);
|
||||
|
||||
// Log gst warnings.
|
||||
s.player.connect_warning(move |_, warn| warn!("gst warning: {}", warn));
|
||||
@ -261,7 +288,7 @@ impl PlayerWidget {
|
||||
|
||||
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||
/// Connect the `PlayerControls` buttons to the `PlayerExt` methods.
|
||||
fn connect_buttons(s: &Rc<Self>) {
|
||||
fn connect_control_buttons(s: &Rc<Self>) {
|
||||
// Connect the play button to the gst Player.
|
||||
s.controls.play.connect_clicked(clone!(s => move |_| s.play()));
|
||||
|
||||
@ -275,6 +302,18 @@ impl PlayerWidget {
|
||||
s.controls.forward.connect_clicked(clone!(s => move |_| s.fast_forward()));
|
||||
}
|
||||
|
||||
#[cfg_attr(rustfmt, rustfmt_skip)]
|
||||
fn connect_rate_buttons(s: &Rc<Self>) {
|
||||
s.rate.radio_normal.connect_toggled(clone!(s => move |_| s.on_rate_changed(1.00)));
|
||||
s.rate.radio125.connect_toggled(clone!(s => move |_| s.on_rate_changed(1.25)));
|
||||
s.rate.radio150.connect_toggled(clone!(s => move |_| s.on_rate_changed(1.50)));
|
||||
}
|
||||
|
||||
fn on_rate_changed(&self, rate: f64) {
|
||||
self.set_playback_rate(rate);
|
||||
self.rate.label.set_text(&format!("{:.2}x", rate));
|
||||
}
|
||||
|
||||
fn reveal(&self) {
|
||||
self.action_bar.show();
|
||||
}
|
||||
@ -370,4 +409,8 @@ impl PlayerExt for PlayerWidget {
|
||||
fn fast_forward(&self) {
|
||||
self.seek(ClockTime::from_seconds(10), SeekDirection::Forward)
|
||||
}
|
||||
|
||||
fn set_playback_rate(&self, rate: f64) {
|
||||
self.player.set_rate(rate);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user