-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathseek_track.rs
23 lines (18 loc) · 874 Bytes
/
seek_track.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use rspotify::{prelude::*, scopes, AuthCodeSpotify, Credentials, OAuth};
fn main() {
// You can use any logger for debugging.
env_logger::init();
// May require the `env-file` feature enabled if the environment variables
// aren't configured manually.
let creds = Credentials::from_env().unwrap();
let oauth = OAuth::from_env(scopes!("user-read-playback-state")).unwrap();
let spotify = AuthCodeSpotify::new(creds, oauth);
// Obtaining the access token
let url = spotify.get_authorize_url(false).unwrap();
// This function requires the `cli` feature enabled.
spotify.prompt_for_token(&url).unwrap();
match spotify.seek_track(chrono::Duration::try_seconds(25).unwrap(), None) {
Ok(_) => println!("Change to previous playback successful"),
Err(_) => eprintln!("Change to previous playback failed"),
}
}