You can find the source-code here:
https://github.com/jishi/Jishi.Intel.SonosUPnP
This is based upon Intels UPnP framework, which is opposed to the COM object that other attempts that I have found, based completely on managed code (no unmanaged code). This makes a huge difference if you are building anything multithreaded (WinForms, WPF etc).
I will try to put up some example code for people to look at.
Right now some of the features are pretty hacky since I'm still learning best practices, but hopefully it simplifies it a bit for someone.
This is built for .NET 4 Client Profile. The requirements is only .NET 4, previous versions doesn't need to exist.
Basic usage is this:
code:
// Create the main object
var discovery = new SonosDiscovery();
// Attach an event handler for topologychanged, this will be triggered as soon as it has found players (and when topology change)
discovery.TopologyChanged += TopologyChanged;
// This will start the UPnP-scanning, this is a manual call so that you are able to setup all event handlers first
discovery.StartScan();
If you want a more descriptive example, you can check out my Dashboard project:
https://github.com/jishi/Panagora.Sonos.Dashboard/blob/master/Panagora.Sonos.Dashboard/MainWindow.xaml.cs
Is a really simple fullscreen app that shows currently playing song for the most relevant player (Biggest group, longest queue).
Any suggestions and feedback is appreciated. As of today it only supports the following features:
Zone discovery
Player status notifications
Play/Pause
Enqueue
Seek (to queue position)
SetAVTransportURI