mirror of
https://github.com/talwat/lowfi
synced 2024-12-26 03:01:55 +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.
|
/// Similar to Next, but specific to the first track.
|
||||||
Init,
|
Init,
|
||||||
|
|
||||||
|
/// Unpause the [Sink].
|
||||||
|
Play,
|
||||||
|
|
||||||
|
/// Pauses the [Sink].
|
||||||
|
Pause,
|
||||||
|
|
||||||
/// Pauses the [Sink]. This will also unpause it if it is paused.
|
/// Pauses the [Sink]. This will also unpause it if it is paused.
|
||||||
PlayPause,
|
PlayPause,
|
||||||
|
|
||||||
@ -305,6 +311,12 @@ impl Player {
|
|||||||
// as to not block the main audio thread.
|
// as to not block the main audio thread.
|
||||||
task::spawn(Self::handle_next(player.clone(), itx.clone(), tx.clone()));
|
task::spawn(Self::handle_next(player.clone(), itx.clone(), tx.clone()));
|
||||||
}
|
}
|
||||||
|
Messages::Play => {
|
||||||
|
player.sink.play();
|
||||||
|
}
|
||||||
|
Messages::Pause => {
|
||||||
|
player.sink.pause();
|
||||||
|
}
|
||||||
Messages::PlayPause => {
|
Messages::PlayPause => {
|
||||||
if player.sink.is_paused() {
|
if player.sink.is_paused() {
|
||||||
player.sink.play();
|
player.sink.play();
|
||||||
|
@ -78,7 +78,7 @@ impl PlayerInterface for Player {
|
|||||||
|
|
||||||
async fn pause(&self) -> fdo::Result<()> {
|
async fn pause(&self) -> fdo::Result<()> {
|
||||||
self.sender
|
self.sender
|
||||||
.send(Messages::PlayPause)
|
.send(Messages::Pause)
|
||||||
.await
|
.await
|
||||||
.map_err(|_| ERROR)
|
.map_err(|_| ERROR)
|
||||||
}
|
}
|
||||||
@ -91,11 +91,14 @@ impl PlayerInterface for Player {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async fn stop(&self) -> fdo::Result<()> {
|
async fn stop(&self) -> fdo::Result<()> {
|
||||||
self.play_pause().await
|
self.pause().await
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn play(&self) -> fdo::Result<()> {
|
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<()> {
|
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::Play => Messages::PlayPause,
|
||||||
event::MediaKeyCode::Pause => Messages::PlayPause,
|
event::MediaKeyCode::Pause => Messages::PlayPause,
|
||||||
event::MediaKeyCode::PlayPause => Messages::PlayPause,
|
event::MediaKeyCode::PlayPause => Messages::PlayPause,
|
||||||
event::MediaKeyCode::Stop => Messages::PlayPause,
|
event::MediaKeyCode::Stop => Messages::Pause,
|
||||||
event::MediaKeyCode::TrackNext => Messages::Next,
|
event::MediaKeyCode::TrackNext => Messages::Next,
|
||||||
event::MediaKeyCode::LowerVolume => Messages::ChangeVolume(-0.1),
|
event::MediaKeyCode::LowerVolume => Messages::ChangeVolume(-0.1),
|
||||||
event::MediaKeyCode::RaiseVolume => Messages::ChangeVolume(0.1),
|
event::MediaKeyCode::RaiseVolume => Messages::ChangeVolume(0.1),
|
||||||
|
Loading…
Reference in New Issue
Block a user