Java Code Examples for org.fourthline.cling.model.meta.Device#findService()

The following examples show how to use org.fourthline.cling.model.meta.Device#findService() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PortMappingListener.java    From TVRemoteIME with GNU General Public License v2.0 6 votes vote down vote up
protected Service discoverConnectionService(Device device) {
    if (!device.getType().equals(IGD_DEVICE_TYPE)) {
        return null;
    }

    Device[] connectionDevices = device.findDevices(CONNECTION_DEVICE_TYPE);
    if (connectionDevices.length == 0) {
        log.fine("IGD doesn't support '" + CONNECTION_DEVICE_TYPE + "': " + device);
        return null;
    }

    Device connectionDevice = connectionDevices[0];
    log.fine("Using first discovered WAN connection device: " + connectionDevice);

    Service ipConnectionService = connectionDevice.findService(IP_SERVICE_TYPE);
    Service pppConnectionService = connectionDevice.findService(PPP_SERVICE_TYPE);

    if (ipConnectionService == null && pppConnectionService == null) {
        log.fine("IGD doesn't support IP or PPP WAN connection service: " + device);
    }

    return ipConnectionService != null ? ipConnectionService : pppConnectionService;
}
 
Example 2
Source File: PlaybackCommand.java    From BeyondUPnP with Apache License 2.0 6 votes vote down vote up
public static void play() {
    Device device = SystemManager.getInstance().getSelectedDevice();
    //Check selected device
    if (device == null) return;

    Service avtService = device.findService(SystemManager.AV_TRANSPORT_SERVICE);
    if (avtService != null) {
        ControlPoint cp = SystemManager.getInstance().getControlPoint();
        cp.execute(new Play(avtService) {
            @Override
            public void success(ActionInvocation invocation) {
                Log.i(TAG, "Play success.");
            }

            @Override
            public void failure(ActionInvocation arg0, UpnpResponse arg1, String arg2) {
                Log.e(TAG, "Play failed");
            }
        });
    }
}
 
Example 3
Source File: PlaybackCommand.java    From BeyondUPnP with Apache License 2.0 6 votes vote down vote up
public static void pause() {
    Device device = SystemManager.getInstance().getSelectedDevice();
    //Check selected device
    if (device == null) return;

    Service avtService = device.findService(SystemManager.AV_TRANSPORT_SERVICE);
    if (avtService != null) {
        ControlPoint cp = SystemManager.getInstance().getControlPoint();
        cp.execute(new Pause(avtService) {
            @Override
            public void success(ActionInvocation invocation) {
                Log.i(TAG, "Pause success.");
            }

            @Override
            public void failure(ActionInvocation arg0, UpnpResponse arg1, String arg2) {
                Log.e(TAG, "Pause failed");
            }
        });
    }
}
 
Example 4
Source File: PlaybackCommand.java    From BeyondUPnP with Apache License 2.0 6 votes vote down vote up
public static void stop() {
    Device device = SystemManager.getInstance().getSelectedDevice();
    //Check selected device
    if (device == null) return;

    Service avtService = device.findService(SystemManager.AV_TRANSPORT_SERVICE);
    if (avtService != null) {
        ControlPoint cp = SystemManager.getInstance().getControlPoint();
        cp.execute(new Stop(avtService) {
            @Override
            public void success(ActionInvocation invocation) {
                Log.i(TAG, "Stop success.");
            }

            @Override
            public void failure(ActionInvocation arg0, UpnpResponse arg1, String arg2) {
                Log.e(TAG, "Stop failed");
            }
        });
    }
}
 
Example 5
Source File: PlaybackCommand.java    From BeyondUPnP with Apache License 2.0 6 votes vote down vote up
public static void getVolume(final Handler handler) {
    Device device = SystemManager.getInstance().getSelectedDevice();
    //Check selected device
    if (device == null) return;

    Service rcService = device.findService(SystemManager.RENDERING_CONTROL_SERVICE);
    if (rcService != null) {
        ControlPoint cp = SystemManager.getInstance().getControlPoint();
        cp.execute(new GetVolume(rcService) {

            @Override
            public void received(ActionInvocation actionInvocation, int currentVolume) {
                //Send currentVolume to handler.
                Log.i(TAG, "GetVolume:" + currentVolume);
                Message msg = Message.obtain(handler, NowplayingFragment.GET_VOLUME_ACTION, currentVolume, 0);
                msg.sendToTarget();
            }

            @Override
            public void failure(ActionInvocation invocation, UpnpResponse operation, String defaultMsg) {
                Log.e(TAG, "GetVolume failed");
            }
        });
    }
}
 
Example 6
Source File: PortMappingListener.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
protected Service discoverConnectionService(Device device) {
    if (!device.getType().equals(IGD_DEVICE_TYPE)) {
        return null;
    }

    Device[] connectionDevices = device.findDevices(CONNECTION_DEVICE_TYPE);
    if (connectionDevices.length == 0) {
        log.fine("IGD doesn't support '" + CONNECTION_DEVICE_TYPE + "': " + device);
        return null;
    }

    Device connectionDevice = connectionDevices[0];
    log.fine("Using first discovered WAN connection device: " + connectionDevice);

    Service ipConnectionService = connectionDevice.findService(IP_SERVICE_TYPE);
    Service pppConnectionService = connectionDevice.findService(PPP_SERVICE_TYPE);

    if (ipConnectionService == null && pppConnectionService == null) {
        log.fine("IGD doesn't support IP or PPP WAN connection service: " + device);
    }

    return ipConnectionService != null ? ipConnectionService : pppConnectionService;
}
 
Example 7
Source File: DMCControl.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
public void seekBarPosition(String paramString) {
	try {
		Device localDevice = this.executeDeviceItem.getDevice();
		Log.e("control action", "seekBarPosition");
		Service localService = localDevice.findService(new UDAServiceType(
				"AVTransport"));
		if (localService != null) {
			Log.e("get seekBarPosition info", "get seekBarPosition info");
			this.upnpService.getControlPoint().execute(
					new SeekCallback(activity, localService, paramString,
							mHandle));
		} else {
			Log.e("null", "null");
		}
	} catch (Exception localException) {
		localException.printStackTrace();
	}
}
 
Example 8
Source File: ContentActivity.java    From DroidDLNA with GNU General Public License v3.0 6 votes vote down vote up
private void initData() {

		mCounter = 0;
		if (null == mSaveDirectoryMap) {
			mSaveDirectoryMap = new HashMap<Integer, ArrayList<ContentItem>>();
		} else {
			mSaveDirectoryMap.clear();
		}
		upnpService = mBaseApplication.upnpService;
		mTitleView.setText(mBaseApplication.deviceItem.toString());
		Device device = mBaseApplication.deviceItem.getDevice();
		Service service = device.findService(new UDAServiceType(
				"ContentDirectory"));
		upnpService.getControlPoint().execute(
				new ContentBrowseActionCallback(ContentActivity.this,
						service, createRootContainer(service), mContentList,
						mHandler));

		mLastDevice = mBaseApplication.deviceItem.toString();
	}
 
Example 9
Source File: ClingRegistryListener.java    From portmapper with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("rawtypes")
private Service<?, ?> findConnectionService(final Device[] connectionDevices) {
    for (final Device connectionDevice : connectionDevices) {

        final Service ipConnectionService = connectionDevice.findService(IP_SERVICE_TYPE);
        final Service pppConnectionService = connectionDevice.findService(PPP_SERVICE_TYPE);

        if (ipConnectionService != null) {
            logger.info("Device {} supports ip service type: {}", connectionDevice, ipConnectionService);
            return ipConnectionService;
        }
        if (pppConnectionService != null) {
            logger.info("Device {} supports ppp service type: {}", connectionDevice, pppConnectionService);
            return pppConnectionService;
        }

        logger.info("IGD {} doesn't support IP or PPP WAN connection service", connectionDevice);
    }
    logger.debug("None of the {} devices supports IP or PPP WAN connections", connectionDevices.length);
    return null;
}
 
Example 10
Source File: RegistryImpl.java    From TVRemoteIME with GNU General Public License v2.0 5 votes vote down vote up
synchronized public Service getService(ServiceReference serviceReference) {
    Device device;
    if ((device = getDevice(serviceReference.getUdn(), false)) != null) {
        return device.findService(serviceReference.getServiceId());
    }
    return null;
}
 
Example 11
Source File: DlnaSearch.java    From HPlayer with Apache License 2.0 5 votes vote down vote up
/**
 * 根据选择的设备 返回DLNA操作集合
 */
public UpnpControlSet createUpnpControlSet(Device device) {
    if (!hadBindService || mUpnpService == null) {
        Log.e(TAG, "had no BindService or mUpnpService is null");
        return null;
    }

    UDAServiceType avTransportServiceType =
            new UDAServiceType(UpnpServiceType.AVTRANSPORT);
    Service avTransportService = device.findService(avTransportServiceType);
    if (avTransportService == null) {
        Log.e(TAG, "avTransportService is null");
        return null;
    }

    UDAServiceType renderingControlServiceType =
            new UDAServiceType(UpnpServiceType.RENDERING_CONTROL);
    Service renderingControlService =
            device.findService(renderingControlServiceType);
    if (renderingControlService == null) {
        Log.e(TAG, "renderingControlService is null");
        return null;
    }

    UpnpControlSet upnpControlSet = new UpnpControlSet(mUpnpService,
            avTransportService, renderingControlService);
    return upnpControlSet;
}
 
Example 12
Source File: ContentContainerActivity.java    From BeyondUPnP with Apache License 2.0 5 votes vote down vote up
private void loadContent() {
    SystemManager systemManager = SystemManager.getInstance();
    Device device = null;
    try {
        device = systemManager.getRegistry().getDevice(new UDN(mIdentifierString), false);
    } catch (NullPointerException e) {
        Log.e(TAG, "Get device error.");
    }

    if (device != null) {
        //Get cds to browse children directories.
        Service contentDeviceService = device.findService(SystemManager.CONTENT_DIRECTORY_SERVICE);
        //Execute Browse action and init list view
        systemManager.getControlPoint().execute(new Browse(contentDeviceService, mObjectId, BrowseFlag.DIRECT_CHILDREN, "*", 0,
                null, new SortCriterion(true, "dc:title")) {
            @Override
            public void received(ActionInvocation actionInvocation, DIDLContent didl) {
                Message msg = Message.obtain(handler,ADD_OBJECTS,didl);
                msg.sendToTarget();
            }

            @Override
            public void updateStatus(Status status) {
            }

            @Override
            public void failure(ActionInvocation invocation, UpnpResponse operation, String defaultMsg) {
            }
        });
    }
}
 
Example 13
Source File: RegistryImpl.java    From DroidDLNA with GNU General Public License v3.0 5 votes vote down vote up
synchronized public Service getService(ServiceReference serviceReference) {
    Device device;
    if ((device = getDevice(serviceReference.getUdn(), false)) != null) {
        return device.findService(serviceReference.getServiceId());
    }
    return null;
}