config.rs 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. use std::str::FromStr;
  2. use core::spotify_id::SpotifyId;
  3. use std::sync::mpsc::Sender;
  4. #[derive(Clone, Copy, Debug, Hash, PartialOrd, Ord, PartialEq, Eq)]
  5. pub enum Bitrate {
  6. Bitrate96,
  7. Bitrate160,
  8. Bitrate320,
  9. }
  10. impl FromStr for Bitrate {
  11. type Err = ();
  12. fn from_str(s: &str) -> Result<Self, Self::Err> {
  13. match s {
  14. "96" => Ok(Bitrate::Bitrate96),
  15. "160" => Ok(Bitrate::Bitrate160),
  16. "320" => Ok(Bitrate::Bitrate320),
  17. _ => Err(()),
  18. }
  19. }
  20. }
  21. impl Default for Bitrate {
  22. fn default() -> Bitrate {
  23. Bitrate::Bitrate160
  24. }
  25. }
  26. #[derive(Debug, Clone)]
  27. pub enum PlayerEvent {
  28. Started {
  29. track_id: SpotifyId,
  30. },
  31. Changed {
  32. old_track_id: SpotifyId,
  33. new_track_id: SpotifyId,
  34. },
  35. Stopped {
  36. track_id: SpotifyId,
  37. }
  38. }
  39. #[derive(Clone, Debug)]
  40. pub struct PlayerConfig {
  41. pub bitrate: Bitrate,
  42. pub event_sender : Option<Sender<PlayerEvent>>,
  43. }
  44. impl Default for PlayerConfig {
  45. fn default() -> PlayerConfig {
  46. PlayerConfig {
  47. bitrate: Bitrate::default(),
  48. event_sender: None,
  49. }
  50. }
  51. }