I am using Cling 1.0.5
I am populating view each time remoteDeviceAdded
is called.
During debug, I see deviceAdded
is first called, then remoteDeviceAdded
Sometimes, remoteDeviceAdded
is not called up, but deviceAdded
would still be called.
So which is to use for discovering remote media renderers?
First, please note that the following pertains to Cling 2.0.1 but I think the logic is the same.
In Cling there's a distinction between a LocalDevice and a RemoteDevice both extending the Device class. One of the main differences between a LocalDevice and a RemoteDevice is that the RemoteDevice is most likely fully hydrated - all of its service XML definitions are parsed and UPnP actions and states are populated in the RemoteDevice object.
When performing a LAN search for devices, Cling doesn't wait for the discovered Device object to be fully hydrated and calls localDeviceAdded()
which in turn calls deviceAdded()
. When this is done, it will call remoteDeviceDiscoveryStarted()
and attempt to fully hydrate the devices found in the search.
If the device was successfully hydrated, then Cling will call remoteDeviceAdded()
which in turn calls deviceAdded()
.
If the device could not be fully hydrated, then Cling will instead call remoteDeviceDiscoveryFailed()
.
Just to make it a bit more graphical:
Start search
+
|
| Device discovered
|
v
calls
LocalDeviceAdded()
+
| calls
| remoteDeviceDiscoveryStarted()
|
v
Attempt to hydrate
+
|
|
calls Success | Failure calls
remoteDeviceAdded() <---------+---------> remoteDeviceDiscoveryFailed()
So now to answer your question, it really depends on what you want to perform in your application:
localDeviceAdded()
remoteDeviceAdded()
.Personally I would go for a third option where I start operating with the LocalDevice (maybe cache it somewhere, or display it) and wait for the device to become a fully hydrated RemoteDevice to read its state and perform actions.