Closed iberflow closed 5 years ago
Hey @ignasbernotas , I know this probably isn't exactly what you want but you might find my mini Spotify client useful - https://github.com/benpye/minispot - I am not using PortAudio though.
In the example in the repo, wg.Wait()
will only return upon hitting https://github.com/librespot-org/librespot-golang/blob/a1bb4bc604d883e54c87a1580929ee5897d5bf21/src/examples/micro-client/main.go#L377 . If you want to be able to return early then you will need some different synchronisation primitive.
My code definitely isn't perfect and I plan to rewrite much of it one day. My goal is to split into two halves, hopefully creating a higher level library that will be more useful (think play playlist, pause track, seek to x, rather than getting the stream, decoding it manually, maybe caching etc as things stand now), and then a client using that. It's definitely a backburner project for me though, I'll hopefully look at it again some day but the initial motivation has passed.
Benpye's repository is indeed a great example. If you otherwise want to start off the official example, a simple trick would be to use goroutines and call wg.Done()
from your HTTP server goroutine into the playback goroutine. This way, you can have both communicating and acting properly.
@benpye oh sweet, this is awesome. I've started tidying up the example code from this repo, so it would be a bit easier for me to understand what's going on, but you've already done that! I think your project is exactly what I need to move forward:) Cheers!
@xplodwild Ah, that makes sense. I'll give it a shot!
Thank you guys!
Hi, I've managed to get the micro-client running (with #12), however I'm stuck on stopping the playback. I'm fairly new to golang so sorry if it's obvious.
https://github.com/librespot-org/librespot-golang/blob/a1bb4bc604d883e54c87a1580929ee5897d5bf21/src/examples/micro-client/main.go#L347
As I understand, I should store the stream variable to be able to later call the
portaudio.StopStream(stream)
, but anything afterwg.Wait()
https://github.com/librespot-org/librespot-golang/blob/a1bb4bc604d883e54c87a1580929ee5897d5bf21/src/examples/micro-client/main.go#L351 doesn't work.I assume
wg.Wait()
blocks the execution till the streaming is over, but I'm stuck on figuring out how to stop the playback.Also, Logging in doesn't register my device (using username/password, username/blob option).
My end goal is to build a binary executable on RaspberryPi which would spawn an HTTP server and I'd be able to play/stop/get playlists/do other stuff via HTTP, but I'd like to be able to stop the playback using the Spotify app as well (though that's not entirely needed). Anyway, what would be the best way to do play/stop via HTTP requests?
I'd be very grateful if you could put me on the right path:) Thanks!