public final class CastDeviceMonitor extends Object
CastDevices while notifying registered listeners of
discovered or disappearing devices.
After creating a CastDeviceMonitor, it must be started using
startDiscovery(InetAddress, String).
| Modifier and Type | Class and Description |
|---|---|
class |
CastDeviceMonitor.MulticastDNSServiceListener
Service listener to receive mDNS service updates.
|
| Modifier and Type | Field and Description |
|---|---|
protected Set<CastDevice> |
castDevices
The currently "registered" cast devices
|
protected CastDeviceMonitor.MulticastDNSServiceListener |
listener
The
ServiceListener that listens to mDNS changes |
protected Set<DeviceDiscoveryListener> |
listeners
The
Set of DeviceDiscoveryListener to notify of changes |
protected Object |
lock
The synchronization object
|
protected javax.jmdns.JmDNS |
mDNS
The mDNS instance
|
| Constructor and Description |
|---|
CastDeviceMonitor()
Creates a new instance.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
finalize() |
Set<CastDevice> |
getCastDevices() |
boolean |
registerListener(DeviceDiscoveryListener listener)
Register a new
DeviceDiscoveryListener that will be notified when
cast devices are found or disappears. |
void |
startDiscovery()
Starts discovery of cast devices.
|
void |
startDiscovery(InetAddress addr,
String name)
Starts discovery of cast devices.
|
void |
stopDiscovery()
Stops discovery of cast devices and removes all discovered devices.
|
void |
stopDiscovery(boolean notifyListeners)
Stops discovery of cast devices and removes all discovered devices.
|
boolean |
unregisterListener(DeviceDiscoveryListener listener)
Unregister a
DeviceDiscoveryListener so that it will no longer be
notified when cast devices are found or disappears. |
@Nonnull protected final CastDeviceMonitor.MulticastDNSServiceListener listener
ServiceListener that listens to mDNS changes@Nullable protected javax.jmdns.JmDNS mDNS
@Nonnull protected final Set<DeviceDiscoveryListener> listeners
Set of DeviceDiscoveryListener to notify of changes@Nonnull protected final Set<CastDevice> castDevices
public CastDeviceMonitor()
startDiscovery() to start
monitoring.public Set<CastDevice> getCastDevices()
Set with a snapshot of the currently known cast
devices.public void startDiscovery()
throws IOException
Note: This is a convenience method. The preferred constructor is
startDiscovery(InetAddress, String). Check that your platform
correctly handles the default localhost IP address and the local
hostname. If in doubt, use the explicit constructor.
This method is equivalent to startDiscovery(null, null).
IOException - If an error occurs during the operation.public void startDiscovery(@Nullable InetAddress addr, @Nullable String name) throws IOException
addr - the IP address to bind to.name - the name of the multicast DNS "device" that will be created
to participate in the "multicast DNS network".IOException - If an error occurs during the operation.public void stopDiscovery()
throws IOException
IOException - If an error occurs during the operation.public void stopDiscovery(boolean notifyListeners)
throws IOException
notifyListeners - if true, also notifies listeners that the
devices are removed, to trigger potential cleanup.IOException - If an error occurs during the operation.protected void finalize()
throws Throwable
public boolean registerListener(@Nullable DeviceDiscoveryListener listener)
DeviceDiscoveryListener that will be notified when
cast devices are found or disappears. It will also be notified of any
already known cast devices at the time of registration before returning.listener - the DeviceDiscoveryListener to add.true if the new listener was registered, false if
it was registered already.public boolean unregisterListener(@Nullable DeviceDiscoveryListener listener)
DeviceDiscoveryListener so that it will no longer be
notified when cast devices are found or disappears.listener - the DeviceDiscoveryListener to remove.true if the listener was unregistered, false if
it wasn't registered before the call.Copyright © 2022. All rights reserved.