Search in sources :

Example 1 with UnsignedIntegerFourBytes

use of org.teleal.cling.model.types.UnsignedIntegerFourBytes in project openhab1-addons by openhab.

the class SonosZonePlayer method getEntries.

protected List<SonosEntry> getEntries(String type, String filter) {
    List<SonosEntry> resultList = null;
    if (isConfigured()) {
        long startAt = 0;
        Service service = device.findService(new UDAServiceId("ContentDirectory"));
        Action action = service.getAction("Browse");
        ActionInvocation invocation = new ActionInvocation(action);
        try {
            invocation.setInput("ObjectID", type);
            invocation.setInput("BrowseFlag", "BrowseDirectChildren");
            invocation.setInput("Filter", filter);
            invocation.setInput("StartingIndex", new UnsignedIntegerFourBytes(startAt));
            invocation.setInput("RequestedCount", new UnsignedIntegerFourBytes(200));
            invocation.setInput("SortCriteria", "");
        } catch (InvalidValueException ex) {
            logger.error("Action Invalid Value Exception {}", ex.getMessage());
        } catch (NumberFormatException ex) {
            logger.error("Action Invalid Value Format Exception {}", ex.getMessage());
        }
        // Execute this action synchronously
        new ActionCallback.Default(invocation, upnpService.getControlPoint()).run();
        Long totalMatches = ((UnsignedIntegerFourBytes) invocation.getOutput("TotalMatches").getValue()).getValue();
        Long initialNumberReturned = ((UnsignedIntegerFourBytes) invocation.getOutput("NumberReturned").getValue()).getValue();
        String initialResult = (String) invocation.getOutput("Result").getValue();
        try {
            resultList = SonosXMLParser.getEntriesFromString(initialResult);
        } catch (SAXException e) {
            logger.error("Could not parse Entries from String {}", initialResult);
        }
        startAt = startAt + initialNumberReturned;
        while (startAt < totalMatches) {
            invocation = new ActionInvocation(action);
            try {
                invocation.setInput("ObjectID", type);
                invocation.setInput("BrowseFlag", "BrowseDirectChildren");
                invocation.setInput("Filter", filter);
                invocation.setInput("StartingIndex", new UnsignedIntegerFourBytes(startAt));
                invocation.setInput("RequestedCount", new UnsignedIntegerFourBytes(200));
                invocation.setInput("SortCriteria", "");
            } catch (InvalidValueException ex) {
                logger.error("Action Invalid Value Exception {}", ex.getMessage());
            } catch (NumberFormatException ex) {
                logger.error("Action Invalid Value Format Exception {}", ex.getMessage());
            }
            // Execute this action synchronously
            new ActionCallback.Default(invocation, upnpService.getControlPoint()).run();
            String result = (String) invocation.getOutput("Result").getValue();
            int numberReturned = (Integer) invocation.getOutput("NumberReturned").getValue();
            try {
                resultList.addAll(SonosXMLParser.getEntriesFromString(result));
            } catch (SAXException e) {
                logger.error("Could not parse Entries from String {}", result);
            }
            startAt = startAt + numberReturned;
        }
    }
    return resultList;
}
Also used : Action(org.teleal.cling.model.meta.Action) ActionCallback(org.teleal.cling.controlpoint.ActionCallback) ActionInvocation(org.teleal.cling.model.action.ActionInvocation) Service(org.teleal.cling.model.meta.Service) UpnpService(org.teleal.cling.UpnpService) SAXException(org.xml.sax.SAXException) InvalidValueException(org.teleal.cling.model.types.InvalidValueException) UnsignedIntegerFourBytes(org.teleal.cling.model.types.UnsignedIntegerFourBytes) UDAServiceId(org.teleal.cling.model.types.UDAServiceId)

Example 2 with UnsignedIntegerFourBytes

use of org.teleal.cling.model.types.UnsignedIntegerFourBytes in project openhab1-addons by openhab.

the class SonosZonePlayer method addURIToQueue.

public boolean addURIToQueue(String URI, String meta, int desiredFirstTrack, boolean enqueueAsNext) {
    if (isConfigured() && URI != null && meta != null) {
        Service service = device.findService(new UDAServiceId("AVTransport"));
        Action action = service.getAction("AddURIToQueue");
        ActionInvocation invocation = new ActionInvocation(action);
        try {
            invocation.setInput("InstanceID", "0");
            invocation.setInput("EnqueuedURI", URI);
            invocation.setInput("EnqueuedURIMetaData", meta);
            invocation.setInput("DesiredFirstTrackNumberEnqueued", new UnsignedIntegerFourBytes(desiredFirstTrack));
            invocation.setInput("EnqueueAsNext", enqueueAsNext);
        } catch (InvalidValueException ex) {
            logger.error("Action Invalid Value Exception {}", ex.getMessage());
        } catch (NumberFormatException ex) {
            logger.error("Action Invalid Value Format Exception {}", ex.getMessage());
        }
        executeActionInvocation(invocation);
        return true;
    }
    return false;
}
Also used : InvalidValueException(org.teleal.cling.model.types.InvalidValueException) Action(org.teleal.cling.model.meta.Action) UnsignedIntegerFourBytes(org.teleal.cling.model.types.UnsignedIntegerFourBytes) ActionInvocation(org.teleal.cling.model.action.ActionInvocation) Service(org.teleal.cling.model.meta.Service) UpnpService(org.teleal.cling.UpnpService) UDAServiceId(org.teleal.cling.model.types.UDAServiceId)

Aggregations

UpnpService (org.teleal.cling.UpnpService)2 ActionInvocation (org.teleal.cling.model.action.ActionInvocation)2 Action (org.teleal.cling.model.meta.Action)2 Service (org.teleal.cling.model.meta.Service)2 InvalidValueException (org.teleal.cling.model.types.InvalidValueException)2 UDAServiceId (org.teleal.cling.model.types.UDAServiceId)2 UnsignedIntegerFourBytes (org.teleal.cling.model.types.UnsignedIntegerFourBytes)2 ActionCallback (org.teleal.cling.controlpoint.ActionCallback)1 SAXException (org.xml.sax.SAXException)1