8000 Add speed control by stpoa · Pull Request #14 · javsanpar/storytel-tui · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add speed control #14

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
22 changes: 22 additions & 0 deletions src/mpv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pub enum Message {
Pause,
Forward,
Backward,
SpeedUp,
SlowDown,
}

pub fn play(siv: &mut Cursive) {
Expand All @@ -25,6 +27,14 @@ pub fn forward(siv: &mut Cursive) {
send_message(siv, Message::Forward);
}

pub fn speed_up(siv: &mut Cursive) {
send_message(siv, Message::SpeedUp)
}

pub fn slow_down(siv: &mut Cursive) {
send_message(siv, Message::SlowDown)
}

pub fn backward(siv: &mut Cursive) {
send_message(siv, Message::Backward);
}
Expand Down Expand Up @@ -100,6 +110,18 @@ pub fn simple_example(
Ok(Message::Backward) => mpv
.command(&["seek", "-5"])
.expect("Error setting MPV property"),
Ok(Message::SpeedUp) => {
let speed: f64 = mpv.get_property("speed").unwrap();
let new_speed: f64 = (speed + 0.25).min(5.0);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm no rust dev, but should min not be max here?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think he is trying to set a max allowed value.
He check min(speed + 0.25 vs 5.0), so the max alowed value will be 5.0.

For example if speed is 5.0 and u try to speed up you will stand on 5.0 due to min check.

On the other hand... I think SpeedDown method is wrong, it should be max.

mpv.set_option("speed", new_speed)
.expect("Error setting MPV property");
},
Ok(Message::SlowDown) => {
let speed: f64 = mpv.get_property("speed").unwrap();
let new_speed: f64 = (speed - 0.25).min(0.5);
mpv.set_option("speed", new_speed)
.expect("Error setting MPV property");
},
_ => break 'main,
};
}
Expand Down
2 changes: 2 additions & 0 deletions src/tui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ fn show_player(siv: &mut Cursive, book_mpv: &(u64, i64, u64)) {
.child(Button::new("Pause", mpv::pause))
.child(Button::new("Backward", mpv::backward))
.child(Button::new("Forward", mpv::forward))
.child(Button::new("Speed+", mpv::speed_up))
.child(Button::new("Speed-", mpv::slow_down))
.child(Button::new("Exit", show_bookshelf)),
)
.title("Player"),
Expand Down
0