mirror of
https://github.com/talwat/lowfi
synced 2024-12-25 18:51:54 +00:00
feat: add play
and pause
messages (#24)
This commit is contained in:
parent
fd8ecfcd05
commit
8d9d003dc9
@ -48,6 +48,12 @@ pub enum Messages {
|
||||
/// Similar to Next, but specific to the first track.
|
||||
Init,
|
||||
|
||||
/// Unpause the [Sink].
|
||||
Play,
|
||||
|
||||
/// Pauses the [Sink].
|
||||
Pause,
|
||||
|
||||
/// Pauses the [Sink]. This will also unpause it if it is paused.
|
||||
PlayPause,
|
||||
|
||||
@ -305,6 +311,12 @@ impl Player {
|
||||
// as to not block the main audio thread.
|
||||
task::spawn(Self::handle_next(player.clone(), itx.clone(), tx.clone()));
|
||||
}
|
||||
Messages::Play => {
|
||||
player.sink.play();
|
||||
}
|
||||
Messages::Pause => {
|
||||
player.sink.pause();
|
||||
}
|
||||
Messages::PlayPause => {
|
||||
if player.sink.is_paused() {
|
||||
player.sink.play();
|
||||
|
@ -78,7 +78,7 @@ impl PlayerInterface for Player {
|
||||
|
||||
async fn pause(&self) -> fdo::Result<()> {
|
||||
self.sender
|
||||
.send(Messages::PlayPause)
|
||||
.send(Messages::Pause)
|
||||
.await
|
||||
.map_err(|_| ERROR)
|
||||
}
|
||||
@ -91,11 +91,14 @@ impl PlayerInterface for Player {
|
||||
}
|
||||
|
||||
async fn stop(&self) -> fdo::Result<()> {
|
||||
self.play_pause().await
|
||||
self.pause().await
|
||||
}
|
||||
|
||||
async fn play(&self) -> fdo::Result<()> {
|
||||
self.play_pause().await
|
||||
self.sender
|
||||
.send(Messages::Play)
|
||||
.await
|
||||
.map_err(|_| ERROR)
|
||||
}
|
||||
|
||||
async fn seek(&self, _offset: Time) -> fdo::Result<()> {
|
||||
|
@ -88,7 +88,7 @@ async fn input(sender: Sender<Messages>) -> eyre::Result<()> {
|
||||
event::MediaKeyCode::Play => Messages::PlayPause,
|
||||
event::MediaKeyCode::Pause => Messages::PlayPause,
|
||||
event::MediaKeyCode::PlayPause => Messages::PlayPause,
|
||||
event::MediaKeyCode::Stop => Messages::PlayPause,
|
||||
event::MediaKeyCode::Stop => Messages::Pause,
|
||||
event::MediaKeyCode::TrackNext => Messages::Next,
|
||||
event::MediaKeyCode::LowerVolume => Messages::ChangeVolume(-0.1),
|
||||
event::MediaKeyCode::RaiseVolume => Messages::ChangeVolume(0.1),
|
||||
|
Loading…
Reference in New Issue
Block a user