mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
d40c0f50db
* create Volume struct for use with Cache * add "volume" file to Cache * load cached volume on start, intial overrides cached overrides default * amend volume_to_mixer function to cache the volume on every change * pass cache to Spirc and SpircTask so volume_to_mixer has access * rustfmt changes * revert volume_to_mixer function and Spirc/SpircTask cache variable * Volume implements Copy, pass by value instead of reference * clamp volume to 100 if cached value exceeds limit * convert Volume to u16 internally, use float and round to convert hex->dec * convert initial_volume and ConnectConfig.volume to u16 as well * add cache_volume function to SpircTask * remove conversion to/from percentage on cached volume * consolidate device.set_volume, mixer.set_volume, and caching * streamline intial volume logic
45 lines
1.3 KiB
Rust
45 lines
1.3 KiB
Rust
extern crate librespot;
|
|
extern crate tokio_core;
|
|
|
|
use std::env;
|
|
use tokio_core::reactor::Core;
|
|
|
|
use librespot::core::authentication::Credentials;
|
|
use librespot::core::config::SessionConfig;
|
|
use librespot::core::session::Session;
|
|
use librespot::core::spotify_id::SpotifyId;
|
|
use librespot::playback::config::PlayerConfig;
|
|
|
|
use librespot::playback::audio_backend;
|
|
use librespot::playback::player::Player;
|
|
|
|
fn main() {
|
|
let mut core = Core::new().unwrap();
|
|
let handle = core.handle();
|
|
|
|
let session_config = SessionConfig::default();
|
|
let player_config = PlayerConfig::default();
|
|
|
|
let args: Vec<_> = env::args().collect();
|
|
if args.len() != 4 {
|
|
println!("Usage: {} USERNAME PASSWORD TRACK", args[0]);
|
|
}
|
|
let username = args[1].to_owned();
|
|
let password = args[2].to_owned();
|
|
let credentials = Credentials::with_password(username, password);
|
|
|
|
let track = SpotifyId::from_base62(&args[3]).unwrap();
|
|
|
|
let backend = audio_backend::find(None).unwrap();
|
|
|
|
println!("Connecting ..");
|
|
let session = core.run(Session::connect(session_config, credentials, None, handle))
|
|
.unwrap();
|
|
|
|
let (player, _) = Player::new(player_config, session.clone(), None, move || (backend)(None));
|
|
|
|
println!("Playing...");
|
|
core.run(player.load(track, true, 0)).unwrap();
|
|
|
|
println!("Done");
|
|
}
|