Added displaying of currently playing song
parent
3f15bad5f3
commit
2d142e0657
|
|
@ -1,5 +1,6 @@
|
||||||
use std::{fs::File, path::PathBuf};
|
use std::{fs::File, path::PathBuf};
|
||||||
|
|
||||||
|
use rmp::PlaylistElement;
|
||||||
use rodio::{OutputStream, OutputStreamHandle, Sink};
|
use rodio::{OutputStream, OutputStreamHandle, Sink};
|
||||||
|
|
||||||
use super::decoder::{Decoder, DecoderImpl, SourceWrapper};
|
use super::decoder::{Decoder, DecoderImpl, SourceWrapper};
|
||||||
|
|
@ -9,12 +10,15 @@ pub struct Playback {
|
||||||
_stream: OutputStream,
|
_stream: OutputStream,
|
||||||
_stream_handle: OutputStreamHandle,
|
_stream_handle: OutputStreamHandle,
|
||||||
sink: Sink,
|
sink: Sink,
|
||||||
|
pub current: Option<Player>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum PlaybackState {
|
#[derive(Clone, Debug, Default)]
|
||||||
Empty,
|
pub struct Player {
|
||||||
Playing,
|
pub track: PlaylistElement,
|
||||||
Paused,
|
pub is_paused: bool,
|
||||||
|
pub duration: Option<f32>,
|
||||||
|
pub position: Option<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Playback {
|
impl Playback {
|
||||||
|
|
@ -26,17 +30,7 @@ impl Playback {
|
||||||
_stream,
|
_stream,
|
||||||
_stream_handle,
|
_stream_handle,
|
||||||
sink,
|
sink,
|
||||||
}
|
current: None,
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_state(&self) -> PlaybackState {
|
|
||||||
// TODO: We know if it's playing but not what is playing. Figure it out later
|
|
||||||
if self.sink.empty() {
|
|
||||||
return PlaybackState::Empty;
|
|
||||||
}
|
|
||||||
match self.sink.is_paused() {
|
|
||||||
true => PlaybackState::Paused,
|
|
||||||
false => PlaybackState::Playing,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -60,6 +54,12 @@ impl Playback {
|
||||||
|
|
||||||
match source {
|
match source {
|
||||||
Some(source) => {
|
Some(source) => {
|
||||||
|
self.current = Some(Player {
|
||||||
|
track: path,
|
||||||
|
is_paused: false,
|
||||||
|
duration: source.total_duration().map(|dur| dur.as_secs_f32()),
|
||||||
|
position: None,
|
||||||
|
});
|
||||||
self.sink.clear();
|
self.sink.clear();
|
||||||
self.sink.append(source);
|
self.sink.append(source);
|
||||||
self.sink.play();
|
self.sink.play();
|
||||||
|
|
@ -70,10 +70,11 @@ impl Playback {
|
||||||
|
|
||||||
/// Toggle playback pause if possible.
|
/// Toggle playback pause if possible.
|
||||||
pub fn toggle_pause(&mut self) {
|
pub fn toggle_pause(&mut self) {
|
||||||
match self.get_state() {
|
if let Some(current) = &self.current {
|
||||||
PlaybackState::Empty => (),
|
match current.is_paused {
|
||||||
PlaybackState::Playing => self.sink.pause(),
|
true => self.sink.play(),
|
||||||
PlaybackState::Paused => self.sink.play(),
|
false => self.sink.pause(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
11
src/ui.rs
11
src/ui.rs
|
|
@ -33,12 +33,11 @@ fn draw_playlist<B: Backend>(f: &mut Frame<B>, app: &App, area: Rect) {
|
||||||
.state
|
.state
|
||||||
.selected()
|
.selected()
|
||||||
.map_or(false, |selected| index == selected);
|
.map_or(false, |selected| index == selected);
|
||||||
// let playing = app
|
let playing = app
|
||||||
// .player_state
|
.playback
|
||||||
// .currently_playing
|
.current
|
||||||
// .clone()
|
.clone()
|
||||||
// .map_or(false, |currently_playing| currently_playing == *path);
|
.map_or(false, |current| current.track == *path);
|
||||||
let playing = false;
|
|
||||||
let mut style = Style::default();
|
let mut style = Style::default();
|
||||||
match (selected, playing) {
|
match (selected, playing) {
|
||||||
(true, false) => {
|
(true, false) => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue