@Override
 public void onDiscoveryRequestChanged(MediaRouteDiscoveryRequest request) {
   if (request != null && request.isActiveScan()) {
     if (dlnaService != null) {
       dlnaService.getControlPoint().search();
     } else {
       searchOnConnect = true;
     }
   }
 }
Example #2
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();
        }
  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);
    }
  }
Example #4
0
 @Override
 public void refresh() {
   upnpService.getControlPoint().search();
 }
  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);
    }
  }