Пример #1
0
 @Override
 public Collection<IUpnpDevice> getDeviceList() {
   ArrayList<IUpnpDevice> deviceList = new ArrayList<IUpnpDevice>();
   if (upnpService != null && upnpService.getRegistry() != null) {
     for (Device device : upnpService.getRegistry().getDevices()) {
       deviceList.add(new CDevice(device));
     }
   }
   return deviceList;
 }
Пример #2
0
  private void addListenerSafe(IRegistryListener registryListener) {
    assert upnpService != null;
    Log.d(TAG, "Add Listener Safe !");

    // Get ready for future device advertisements
    upnpService.getRegistry().addListener(new CRegistryListener(registryListener));

    // Now add all devices to the list we already know about
    for (Device device : upnpService.getRegistry().getDevices()) {
      registryListener.deviceAdded(new CDevice(device));
    }
  }
Пример #3
0
  @Override
  public Collection<IUpnpDevice> getFilteredDeviceList(ICallableFilter filter) {
    ArrayList<IUpnpDevice> deviceList = new ArrayList<IUpnpDevice>();
    try {
      if (upnpService != null && upnpService.getRegistry() != null) {
        for (Device device : upnpService.getRegistry().getDevices()) {
          IUpnpDevice upnpDevice = new CDevice(device);
          filter.setDevice(upnpDevice);

          if (filter.call()) deviceList.add(upnpDevice);
        }
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return deviceList;
  }
Пример #4
0
 // Implementation of ServiceConnectionInterface
 @Override
 public void onServiceConnected(ComponentName componentName, IBinder binder) {
   if (binder instanceof AndroidUpnpService) {
     androidUpnpService = (AndroidUpnpService) binder;
     localDevice = createDevice();
     androidUpnpService.getRegistry().addDevice(localDevice);
   }
 }
Пример #5
0
 @Override
 public void onDiscoveryRequestChanged(MediaRouteDiscoveryRequest request) {
   if (request != null && request.isActiveScan()) {
     if (dlnaService != null) {
       dlnaService.getControlPoint().search();
     } else {
       searchOnConnect = true;
     }
   }
 }
Пример #6
0
        @Override
        public void onServiceConnected(ComponentName className, IBinder service) {
          Log.d(TAG, "Service connexion");
          upnpService = (AndroidUpnpService) service;

          for (IRegistryListener registryListener : waitingListener) {
            addListenerSafe(registryListener);
          }

          // Search asynchronously for all devices, they will respond soon
          upnpService.getControlPoint().search();
        }
Пример #7
0
  private void deviceRemoved(Device device) {
    if (device.getType().getType().equals("MediaRenderer") && device instanceof RemoteDevice) {
      final String id = device.getIdentity().getUdn().toString();
      removing.add(id);

      // Delay removal for a few seconds to make sure that it isn't just a temp disconnect
      dlnaService.getControlPoint().search();
      downloadService.postDelayed(
          new Runnable() {
            @Override
            public void run() {
              if (removing.contains(id)) {
                devices.remove(id);
                removing.remove(id);
                broadcastDescriptors();
              }
            }
          },
          5000L);
    }
  }
Пример #8
0
 @Override
 public void refresh() {
   upnpService.getControlPoint().search();
 }
Пример #9
0
 private void removeListenerSafe(IRegistryListener registryListener) {
   assert upnpService != null;
   Log.d(TAG, "remove listener Safe");
   upnpService.getRegistry().removeListener(new CRegistryListener(registryListener));
 }
Пример #10
0
  private void deviceAdded(final Device device) {
    final org.fourthline.cling.model.meta.Service renderingControl =
        device.findService(new ServiceType("schemas-upnp-org", "RenderingControl"));
    if (renderingControl == null) {
      return;
    }

    final String id = device.getIdentity().getUdn().toString();
    // In the process of looking up it's details already
    if (adding.contains(id)) {
      return;
    }
    // Just a temp disconnect, already have it's info
    if (removing.contains(id)) {
      removing.remove(id);
      return;
    }
    adding.add(id);

    if (device.getType().getType().equals("MediaRenderer") && device instanceof RemoteDevice) {
      try {
        dlnaService
            .getControlPoint()
            .execute(
                new GetVolume(renderingControl) {
                  @Override
                  public void received(ActionInvocation actionInvocation, int currentVolume) {
                    int maxVolume = 100;
                    StateVariable volume = renderingControl.getStateVariable("Volume");
                    if (volume != null) {
                      StateVariableAllowedValueRange volumeRange =
                          volume.getTypeDetails().getAllowedValueRange();
                      maxVolume = (int) volumeRange.getMaximum();
                    }

                    // Create a new DLNADevice to represent this item
                    String id = device.getIdentity().getUdn().toString();
                    String name = device.getDetails().getFriendlyName();
                    String displayName = device.getDisplayString();

                    DLNADevice newDevice =
                        new DLNADevice(device, id, name, displayName, currentVolume, maxVolume);
                    devices.put(id, newDevice);
                    downloadService.post(
                        new Runnable() {
                          @Override
                          public void run() {
                            broadcastDescriptors();
                          }
                        });
                    adding.remove(id);
                  }

                  @Override
                  public void failure(
                      ActionInvocation actionInvocation, UpnpResponse upnpResponse, String s) {
                    Log.w(TAG, "Failed to get default volume for DLNA route");
                    Log.w(TAG, "Reason: " + s);
                    adding.remove(id);
                  }
                });
      } catch (Exception e) {
        Log.e(TAG, "Failed to add device", e);
      }
    } else {
      adding.remove(id);
    }
  }
Пример #11
0
 @Override
 public void onServiceDisconnected(ComponentName componentName) {
   androidUpnpService.getRegistry().removeDevice(localDevice);
 }