janbar / noson

C++ library for accessing SONOS devices.
GNU General Public License v3.0
27 stars 8 forks source link

Documentation questions #11

Open buelowp opened 3 years ago

buelowp commented 3 years ago

Hi, so far, love the concept. but I'm having some issues figuring out how to use this library. My goal is a QT C++ implementation to add into a QT frontend I have in my living room that shows a clock, TV metadata, and some other information from around the house. I would love to use noson to add to that the ability to show what's on my speakers when they are playing.

I'm using the noson test.cpp as a jumping off point, and am digging into the source (doxygen and source actually). However, I'm having some trouble identifying how to use the API effectively. I have been able to follow the test.cpp code to list my players and zones in a test UI, but what I'm having trouble with is identifying HOW to use a player object to get status of when something starts to play, get the player metadata and album art, and what is the callback used for and how? More importantly, how does one use the handle to determine context? I can see that a callback is fired in Player::CB_RenderingControl, but I don't know why, or how to determine from the handle that this is what happened.

So, what I'm asking for is a small documented API getting started guide. The doxygen doesn't actually tell me how Discover() works, or how GetPlayer works, or how to use those things to cobble together a useful implementation. Google isn't showing me any existing apps that used the library directly, so I can't find someone else who has figured this out already.

Also, as I dig into the code, would you be willing to accept documentation updates as patches if I can (or have time) to do them? Doxygen can be very powerful if you have a main page with some examples and then each function tells why it's used and other details.

janbar commented 3 years ago

Hi, I will try to add a sample of code here. For instance you could have a look in my Qt app how I handle things:

https://github.com/janbar/noson-app/blob/master/backend/NosonApp/player.cpp

https://github.com/janbar/noson-app/blob/master/backend/NosonApp/sonos.cpp

And a very simple case in the CLI tool, there:

https://github.com/janbar/noson-app/blob/master/backend/cli/noson.cpp

So the devices (Sonos) use the Upnp protocol, and it is quite complex to manage correctly things because all responses are asynchronous. That the reason of the callback.

buelowp commented 3 years ago

Thank you, I hadn't seen your QT example. That does make it a bit easier to understand.

I understand why you need a callback, what I'm having trouble with is how to use the callback structure you implemented. I do see some more usage in the sonos.cpp file, so maybe I can use that to work on figuring it out. You're right about upnp, but some examples/explanations on how your code does things would be much appreciated.

If you would put together a couple of simple examples, such as, how to get currently playing metadata for any speaker in the house, how to play a song on a specific speaker/zone, and how to use the OAuth setup you have to communicate with the Sonos backend, I think a lot of good would come from that from more people than just me.

buelowp commented 2 months ago

@janbar, long time, but I finally got back around to this. I have it working now, but I still am having issues with how to use the callback in any context. It's not clear what that callback tells me, as the API's seem to return the data I need when I need it. For now, I'm ignoring it, as I just have a query interface so I can display what the Sonos is currently playing for a given Zone. I basically request data from the Zone, and display it when it's returned.

Thanks for this though, I had abandoned it for 4 years just because I didn't have time. However, I took a few hours tonight and was able to replace the Node SONOS implementation I had for yours and I think it's going to be a good change all over.