Search in sources :

Example 1 with SonosMusicService

use of org.eclipse.smarthome.binding.sonos.internal.SonosMusicService in project smarthome by eclipse.

the class ZonePlayerHandler method getAvailableMusicServices.

private List<SonosMusicService> getAvailableMusicServices() {
    if (musicServices == null) {
        Map<String, String> result = service.invokeAction(this, "MusicServices", "ListAvailableServices", null);
        if (result.get("AvailableServiceDescriptorList") != null) {
            musicServices = SonosXMLParser.getMusicServicesFromXML(result.get("AvailableServiceDescriptorList"));
            String[] servicesTypes = new String[0];
            if (result.get("AvailableServiceTypeList") != null) {
                // It is a comma separated list of service types (integers) in the same order as the services
                // declaration in "AvailableServiceDescriptorList" except that there is no service type for the
                // TuneIn service
                servicesTypes = result.get("AvailableServiceTypeList").split(",");
            }
            int idx = 0;
            for (SonosMusicService service : musicServices) {
                if (!service.getName().equals("TuneIn")) {
                    // except TuneIn
                    if (idx < servicesTypes.length) {
                        try {
                            Integer serviceType = Integer.parseInt(servicesTypes[idx]);
                            service.setType(serviceType);
                        } catch (NumberFormatException e) {
                        }
                        idx++;
                    }
                } else {
                    // Use 65031 as service type value for TuneIn service
                    service.setType(65031);
                }
                logger.debug("Service name {} => id {} type {}", service.getName(), service.getId(), service.getType());
            }
        }
    }
    return musicServices;
}
Also used : SonosMusicService(org.eclipse.smarthome.binding.sonos.internal.SonosMusicService)

Example 2 with SonosMusicService

use of org.eclipse.smarthome.binding.sonos.internal.SonosMusicService in project smarthome by eclipse.

the class ZonePlayerHandler method playTuneinStation.

public void playTuneinStation(Command command) {
    if (command instanceof StringType) {
        String stationId = command.toString();
        List<SonosMusicService> allServices = getAvailableMusicServices();
        SonosMusicService tuneinService = null;
        // search for the TuneIn music service based on its name
        if (allServices != null) {
            for (SonosMusicService service : allServices) {
                if (service.getName().equals("TuneIn")) {
                    tuneinService = service;
                    break;
                }
            }
        }
        // set the URI of the group coordinator
        if (tuneinService != null) {
            try {
                ZonePlayerHandler coordinator = getCoordinatorHandler();
                SonosEntry entry = new SonosEntry("", "TuneIn station", "", "", "", "", "object.item.audioItem.audioBroadcast", String.format(TUNEIN_URI, stationId, tuneinService.getId()));
                entry.setDesc("SA_RINCON" + tuneinService.getType().toString() + "_");
                coordinator.setCurrentURI(entry);
                coordinator.play();
            } catch (IllegalStateException e) {
                logger.debug("Cannot play TuneIn station {} ({})", stationId, e.getMessage());
            }
        } else {
            logger.debug("TuneIn service not found");
        }
    }
}
Also used : SonosMusicService(org.eclipse.smarthome.binding.sonos.internal.SonosMusicService) SonosEntry(org.eclipse.smarthome.binding.sonos.internal.SonosEntry) StringType(org.eclipse.smarthome.core.library.types.StringType)

Aggregations

SonosMusicService (org.eclipse.smarthome.binding.sonos.internal.SonosMusicService)2 SonosEntry (org.eclipse.smarthome.binding.sonos.internal.SonosEntry)1 StringType (org.eclipse.smarthome.core.library.types.StringType)1