Jelajahi Sumber

core API: move Bitrate and PlayerConfig from core to playback

awiouy 7 tahun lalu
induk
melakukan
191caca518
6 mengubah file dengan 48 tambahan dan 45 penghapusan
  1. 0 42
      core/src/config.rs
  2. 1 1
      examples/play.rs
  3. 43 0
      playback/src/config.rs
  4. 1 0
      playback/src/lib.rs
  5. 1 1
      playback/src/player.rs
  6. 2 1
      src/main.rs

+ 0 - 42
core/src/config.rs

@@ -20,31 +20,6 @@ impl Default for SessionConfig {
     }
 }
 
-#[derive(Clone, Copy, Debug, Hash, PartialOrd, Ord, PartialEq, Eq)]
-pub enum Bitrate {
-    Bitrate96,
-    Bitrate160,
-    Bitrate320,
-}
-
-impl FromStr for Bitrate {
-    type Err = ();
-    fn from_str(s: &str) -> Result<Self, Self::Err> {
-        match s {
-            "96" => Ok(Bitrate::Bitrate96),
-            "160" => Ok(Bitrate::Bitrate160),
-            "320" => Ok(Bitrate::Bitrate320),
-            _ => Err(()),
-        }
-    }
-}
-
-impl Default for Bitrate {
-    fn default() -> Bitrate {
-        Bitrate::Bitrate160
-    }
-}
-
 #[derive(Clone, Copy, Debug, Hash, PartialOrd, Ord, PartialEq, Eq)]
 pub enum DeviceType {
     Unknown = 0,
@@ -99,23 +74,6 @@ impl Default for DeviceType {
     }
 }
 
-#[derive(Clone, Debug)]
-pub struct PlayerConfig {
-    pub bitrate: Bitrate,
-    pub onstart: Option<String>,
-    pub onstop: Option<String>,
-}
-
-impl Default for PlayerConfig {
-    fn default() -> PlayerConfig {
-        PlayerConfig {
-            bitrate: Bitrate::default(),
-            onstart: None,
-            onstop: None,
-        }
-    }
-}
-
 #[derive(Clone, Debug)]
 pub struct ConnectConfig {
     pub name: String,

+ 1 - 1
examples/play.rs

@@ -5,7 +5,7 @@ use std::env;
 use tokio_core::reactor::Core;
 
 use librespot::core::authentication::Credentials;
-use librespot::core::config::{PlayerConfig, SessionConfig};
+use librespot::playback::config::{PlayerConfig, SessionConfig};
 use librespot::core::session::Session;
 use librespot::core::util::SpotifyId;
 

+ 43 - 0
playback/src/config.rs

@@ -0,0 +1,43 @@
+use std::str::FromStr;
+
+#[derive(Clone, Copy, Debug, Hash, PartialOrd, Ord, PartialEq, Eq)]
+pub enum Bitrate {
+    Bitrate96,
+    Bitrate160,
+    Bitrate320,
+}
+
+impl FromStr for Bitrate {
+    type Err = ();
+    fn from_str(s: &str) -> Result<Self, Self::Err> {
+        match s {
+            "96" => Ok(Bitrate::Bitrate96),
+            "160" => Ok(Bitrate::Bitrate160),
+            "320" => Ok(Bitrate::Bitrate320),
+            _ => Err(()),
+        }
+    }
+}
+
+impl Default for Bitrate {
+    fn default() -> Bitrate {
+        Bitrate::Bitrate160
+    }
+}
+
+#[derive(Clone, Debug)]
+pub struct PlayerConfig {
+    pub bitrate: Bitrate,
+    pub onstart: Option<String>,
+    pub onstop: Option<String>,
+}
+
+impl Default for PlayerConfig {
+    fn default() -> PlayerConfig {
+        PlayerConfig {
+            bitrate: Bitrate::default(),
+            onstart: None,
+            onstop: None,
+        }
+    }
+}

+ 1 - 0
playback/src/lib.rs

@@ -22,5 +22,6 @@ extern crate librespot_core as core;
 extern crate librespot_metadata as metadata;
 
 pub mod audio_backend;
+pub mod config;
 pub mod mixer;
 pub mod player;

+ 1 - 1
playback/src/player.rs

@@ -9,7 +9,7 @@ use std::sync::mpsc::{RecvError, TryRecvError, RecvTimeoutError};
 use std::thread;
 use std::time::Duration;
 
-use core::config::{Bitrate, PlayerConfig};
+use config::{Bitrate, PlayerConfig};
 use core::session::Session;
 use core::util::SpotifyId;
 

+ 2 - 1
src/main.rs

@@ -20,11 +20,12 @@ use std::mem;
 
 use librespot::core::authentication::{get_credentials, Credentials};
 use librespot::core::cache::Cache;
-use librespot::core::config::{Bitrate, DeviceType, PlayerConfig, SessionConfig, ConnectConfig};
+use librespot::core::config::{DeviceType, SessionConfig, ConnectConfig};
 use librespot::core::session::Session;
 use librespot::core::version;
 
 use librespot::playback::audio_backend::{self, Sink, BACKENDS};
+use librespot::playback::config::{Bitrate, PlayerConfig};
 use librespot::discovery::discovery::{discovery, DiscoveryStream};
 use librespot::playback::mixer::{self, Mixer};
 use librespot::playback::player::Player;