[GH-ISSUE #104] read from STDIN while playing a track #92

Closed
opened 2026-02-27 19:28:47 +03:00 by kerem · 1 comment
Owner

Originally created by @sashahilton00 on GitHub (Jan 29, 2018).
Original GitHub issue: https://github.com/librespot-org/librespot/issues/104

Issue by wijnanb
Monday Jan 22, 2018 at 21:28 GMT
Originally opened as https://github.com/plietar/librespot/issues/274


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?

Originally created by @sashahilton00 on GitHub (Jan 29, 2018). Original GitHub issue: https://github.com/librespot-org/librespot/issues/104 <a href="https://github.com/wijnanb"><img src="https://avatars3.githubusercontent.com/u/506488?v=4" align="left" width="96" height="96" hspace="10"></img></a> **Issue by [wijnanb](https://github.com/wijnanb)** _Monday Jan 22, 2018 at 21:28 GMT_ _Originally opened as https://github.com/plietar/librespot/issues/274_ ---- I am trying to adapt the [play.rs](https://github.com/plietar/librespot/blob/master/examples/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?
Author
Owner

@ComlOnline commented on GitHub (Jan 29, 2018):

Hey @wijnanb, Please see #105 for more information on controlling from the command line. I don't think that this is something that we would be wanting for librespot and it's not meant to be controlled directly.

<!-- gh-comment-id:361316420 --> @ComlOnline commented on GitHub (Jan 29, 2018): Hey @wijnanb, Please see #105 for more information on controlling from the command line. I don't think that this is something that we would be wanting for librespot and it's not meant to be controlled directly.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/librespot#92
No description provided.