plietar / librespot

Open Source Spotify client library
MIT License
1.13k stars 187 forks source link

read from STDIN while playing a track #274

Open wijnanb opened 6 years ago

wijnanb commented 6 years ago

I am trying to adapt the play.rs example to make it able to be controlled via STDIN. As my experience with Rust is very minimal i am struggling with handling non-blocking IO.

My code is as follows:

loop {
        println!("Waiting for input");
        let stdin = std::io::stdin();
        let l = stdin.lock().lines().next().unwrap().unwrap();
        println!("Received input: {}", line);

        let next_track = SpotifyId::from_base62(&line);

        println!("Playing next track... {}", line);
        core.run(player.load(next_track, true, 0)).unwrap();
        // execution on this thread is blocked?
    }

How can we interrupt the execution of `core.run()?

I have been reading on core::handle and core::remote but since I am used to node.js I am feeling a bit lost here ... ;-)

Can someone point me in the right direction?