librespot/examples/play.rs

42 lines
1.1 KiB
Rust
Raw Normal View History

2017-04-28 22:24:55 +00:00
use std::env;
2019-10-07 21:19:45 +00:00
use librespot::core::authentication::Credentials;
use librespot::core::config::SessionConfig;
use librespot::core::session::Session;
use librespot::core::spotify_id::SpotifyId;
2018-02-22 12:24:04 +00:00
use librespot::playback::audio_backend;
2021-04-01 16:10:42 +00:00
use librespot::playback::config::PlayerConfig;
2020-02-02 00:07:05 +00:00
use librespot::playback::player::Player;
2017-04-28 22:24:55 +00:00
#[tokio::main]
async fn main() {
2017-08-03 19:11:30 +00:00
let session_config = SessionConfig::default();
let player_config = PlayerConfig::default();
2017-04-28 22:24:55 +00:00
2018-02-26 01:50:41 +00:00
let args: Vec<_> = env::args().collect();
2017-04-28 22:24:55 +00:00
if args.len() != 4 {
eprintln!("Usage: {} USERNAME PASSWORD TRACK", args[0]);
return;
2017-04-28 22:24:55 +00:00
}
let credentials = Credentials::with_password(&args[1], &args[2]);
2017-04-28 22:24:55 +00:00
2018-02-25 02:04:07 +00:00
let track = SpotifyId::from_base62(&args[3]).unwrap();
2017-04-28 22:24:55 +00:00
let backend = audio_backend::find(None).unwrap();
println!("Connecting ..");
2021-04-01 16:10:42 +00:00
let session = Session::connect(session_config, credentials, None)
.await
.unwrap();
2017-04-28 22:24:55 +00:00
2021-04-01 16:10:42 +00:00
let (mut player, _) = Player::new(player_config, session, None, move || backend(None));
2017-04-28 22:24:55 +00:00
2020-02-02 00:07:05 +00:00
player.load(track, true, 0);
2017-04-28 22:24:55 +00:00
println!("Playing...");
player.await_end_of_track().await;
2017-04-28 22:24:55 +00:00
println!("Done");
}