I'm in C#, so this isn't an easy translation, but here's my version of
FindZonePlayers. I'm using log4net from the Apache Foundation, which
I highly recommend you switch to rather than rolling your own logging.
public class DeviceFinder
{
public class ZonePlayerInfo
{
public ZonePlayerInfo(string name, string id)
{
Name = name;
DeviceId = id;
}
public string DeviceId { get; private set; }
public string Name { get; private set; }
}
public List<ZonePlayerInfo> FindZonePlayers()
{
object obj2;
UPnPDeviceFinder finder = new UPnPDeviceFinderClass();
object[] vInActionArgs = new object[1];
object[] objArray2 = new object[1];
try
{
UPnPDevices devices = finder.FindByType("urn:schemas-upnp-
org:device:ZonePlayer:1", 0);
if (devices.Count == 0)
{
return null;
}
var zones = new List<ZonePlayerInfo>();
object[] attrs = new object[1];
foreach (UPnPDevice device in devices)
{
device.Services["urn:upnp-
org:serviceId:DeviceProperties"].InvokeAction("GetZoneAttributes",
vInActionArgs, ref attrs);
zones.Add(new ZonePlayerInfo(attrs[0], device.UniqueDeviceName));
}
return zones;
}
catch (Exception exception)
{
_Log.Warn("FindZonePlayers failed", exception);
return null;
}
}
}