core API: move Bitrate and PlayerConfig from core to playback

This commit is contained in:
awiouy 2018-02-11 16:13:42 +01:00
parent 685c607c15
commit 191caca518
6 changed files with 48 additions and 45 deletions

View file

@ -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)] #[derive(Clone, Copy, Debug, Hash, PartialOrd, Ord, PartialEq, Eq)]
pub enum DeviceType { pub enum DeviceType {
Unknown = 0, 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)] #[derive(Clone, Debug)]
pub struct ConnectConfig { pub struct ConnectConfig {
pub name: String, pub name: String,

View file

@ -5,7 +5,7 @@ use std::env;
use tokio_core::reactor::Core; use tokio_core::reactor::Core;
use librespot::core::authentication::Credentials; 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::session::Session;
use librespot::core::util::SpotifyId; use librespot::core::util::SpotifyId;

43
playback/src/config.rs Normal file
View file

@ -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,
}
}
}

View file

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

View file

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

View file

@ -20,11 +20,12 @@ use std::mem;
use librespot::core::authentication::{get_credentials, Credentials}; use librespot::core::authentication::{get_credentials, Credentials};
use librespot::core::cache::Cache; 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::session::Session;
use librespot::core::version; use librespot::core::version;
use librespot::playback::audio_backend::{self, Sink, BACKENDS}; use librespot::playback::audio_backend::{self, Sink, BACKENDS};
use librespot::playback::config::{Bitrate, PlayerConfig};
use librespot::discovery::discovery::{discovery, DiscoveryStream}; use librespot::discovery::discovery::{discovery, DiscoveryStream};
use librespot::playback::mixer::{self, Mixer}; use librespot::playback::mixer::{self, Mixer};
use librespot::playback::player::Player; use librespot::playback::player::Player;