support configuration of audio backend and backend device

fixes #194
This commit is contained in:
Henrik Friedrichsen
2020-05-19 00:05:32 +02:00
parent d04766160d
commit 91ce808ef8
4 changed files with 12 additions and 2 deletions

View File

@@ -122,6 +122,8 @@ values are:
* `use_nerdfont`: Turn nerdfont glyphs on/off <true/false>
* `theme`: Set a custom color palette (see below)
* `backend`: Audio backend to use, run `ncspot -h` for a list of devices
* `backend_device`: Audio device string to configure the backend
* `audio_cache`: Enable or disable caching of audio files, on by default
<true/false>
* `volnorm`: Enable or disable volume normalization, off by default <true/false>

View File

@@ -14,6 +14,8 @@ pub struct Config {
pub use_nerdfont: Option<bool>,
pub saved_state: Option<SavedState>,
pub audio_cache: Option<bool>,
pub backend: Option<String>,
pub backend_device: Option<String>,
pub volnorm: Option<bool>,
pub volnorm_pregain: Option<f32>,
}

View File

@@ -49,6 +49,7 @@ use cursive::Cursive;
use librespot_core::authentication::Credentials;
use librespot_core::cache::Cache;
use librespot_playback::audio_backend;
mod album;
mod artist;
@@ -121,10 +122,15 @@ fn credentials_prompt(reset: bool) -> Credentials {
}
fn main() {
let backends = {
let backends: Vec<&str> = audio_backend::BACKENDS.iter().map(|b| b.0).collect();
format!("Audio backends: {}", backends.join(", "))
};
let matches = App::new("ncspot")
.version(env!("CARGO_PKG_VERSION"))
.author("Henrik Friedrichsen <henrik@affekt.org> and contributors")
.about("cross-platform ncurses Spotify client")
.after_help(&*backends)
.arg(
Arg::with_name("debug")
.short("d")

View File

@@ -373,12 +373,12 @@ impl Spotify {
let mixer = create_mixer(None);
mixer.set_volume(volume);
let backend = audio_backend::find(None).unwrap();
let backend = audio_backend::find(cfg.backend.clone()).unwrap();
let (player, _eventchannel) = Player::new(
player_config,
session.clone(),
mixer.get_audio_filter(),
move || (backend)(None),
move || (backend)(cfg.backend_device),
);
let worker = Worker::new(events, commands, session, player, mixer);