Search in sources :

Example 6 with SonosEntry

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

the class ZonePlayerHandler method playPlayList.

public void playPlayList(Command command) {
    if (command != null && command instanceof StringType) {
        String playlist = command.toString();
        List<SonosEntry> playlists = getPlayLists();
        SonosEntry theEntry = null;
        // search for the appropriate play list based on its name (title)
        for (SonosEntry somePlaylist : playlists) {
            if (somePlaylist.getTitle().equals(playlist)) {
                theEntry = somePlaylist;
                break;
            }
        }
        // set the URI of the group coordinator
        if (theEntry != null) {
            try {
                ZonePlayerHandler coordinator = getCoordinatorHandler();
                coordinator.addURIToQueue(theEntry);
                coordinator.setCurrentURI(QUEUE_URI + coordinator.getUDN() + "#0", "");
                String firstTrackNumberEnqueued = stateMap.get("FirstTrackNumberEnqueued");
                if (firstTrackNumberEnqueued != null) {
                    coordinator.seek("TRACK_NR", firstTrackNumberEnqueued);
                }
                coordinator.play();
            } catch (IllegalStateException e) {
                logger.debug("Cannot play playlist ({})", e.getMessage());
            }
        } else {
            logger.debug("Playlist '{}' not found", playlist);
        }
    }
}
Also used : SonosEntry(org.eclipse.smarthome.binding.sonos.internal.SonosEntry) StringType(org.eclipse.smarthome.core.library.types.StringType)

Example 7 with SonosEntry

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

the class ZonePlayerHandler method restoreState.

/**
 * Restore the state (track, position etc) of the Sonos Zone player.
 *
 * @return true if no error occurred.
 */
protected void restoreState() {
    synchronized (stateLock) {
        if (savedState != null) {
            // put settings back
            if (savedState.volume != null) {
                setVolume(DecimalType.valueOf(savedState.volume));
            }
            if (isCoordinator()) {
                if (savedState.entry != null) {
                    // check if we have a playlist to deal with
                    if (savedState.entry.getUpnpClass().contains("object.container.playlistContainer")) {
                        addURIToQueue(savedState.entry.getRes(), SonosXMLParser.compileMetadataString(savedState.entry), 0, true);
                        SonosEntry entry = new SonosEntry("", "", "", "", "", "", "", QUEUE_URI + getUDN() + "#0");
                        setCurrentURI(entry);
                        setPositionTrack(savedState.track);
                    } else {
                        setCurrentURI(savedState.entry);
                        setPosition(savedState.relTime);
                    }
                }
                if (savedState.transportState != null) {
                    if (savedState.transportState.equals(STATE_PLAYING)) {
                        play();
                    } else if (savedState.transportState.equals(STATE_STOPPED)) {
                        stop();
                    } else if (savedState.transportState.equals(STATE_PAUSED_PLAYBACK)) {
                        pause();
                    }
                }
            }
        }
    }
}
Also used : SonosEntry(org.eclipse.smarthome.binding.sonos.internal.SonosEntry)

Example 8 with SonosEntry

use of org.eclipse.smarthome.binding.sonos.internal.SonosEntry 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)

Example 9 with SonosEntry

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

the class ZonePlayerHandler method saveState.

/**
 * Save the state (track, position etc) of the Sonos Zone player.
 *
 * @return true if no error occurred.
 */
protected void saveState() {
    synchronized (stateLock) {
        savedState = new SonosZonePlayerState();
        String currentURI = getCurrentURI();
        savedState.transportState = getTransportState();
        savedState.volume = getVolume();
        if (currentURI != null) {
            if (isPlayingStream(currentURI) || isPlayingRadio(currentURI)) {
                // we are streaming music, like tune-in radio or Google Play Music radio
                SonosMetaData track = getTrackMetadata();
                SonosMetaData current = getCurrentURIMetadata();
                if (track != null && current != null) {
                    savedState.entry = new SonosEntry("", current.getTitle(), "", "", track.getAlbumArtUri(), "", current.getUpnpClass(), currentURI);
                }
            } else if (currentURI.contains(GROUP_URI)) {
                // we are a slave to some coordinator
                savedState.entry = new SonosEntry("", "", "", "", "", "", "", currentURI);
            } else if (isPlayingLineIn(currentURI)) {
                // we are streaming from the Line In connection
                savedState.entry = new SonosEntry("", "", "", "", "", "", "", currentURI);
            } else if (isPlayingQueue(currentURI)) {
                // we are playing something that sits in the queue
                SonosMetaData queued = getEnqueuedTransportURIMetaData();
                if (queued != null) {
                    savedState.track = getCurrenTrackNr();
                    if (queued.getUpnpClass().contains("object.container.playlistContainer")) {
                        // we are playing a real 'saved' playlist
                        List<SonosEntry> playLists = getPlayLists();
                        for (SonosEntry someList : playLists) {
                            if (someList.getTitle().equals(queued.getTitle())) {
                                savedState.entry = new SonosEntry(someList.getId(), someList.getTitle(), someList.getParentId(), "", "", "", someList.getUpnpClass(), someList.getRes());
                                break;
                            }
                        }
                    } else if (queued.getUpnpClass().contains("object.container")) {
                        // we are playing some other sort of
                        // 'container' - we will save that to a
                        // playlist for our convenience
                        logger.debug("Save State for a container of type {}", queued.getUpnpClass());
                        // save the playlist
                        String existingList = "";
                        List<SonosEntry> playLists = getPlayLists();
                        for (SonosEntry someList : playLists) {
                            if (someList.getTitle().equals(ESH_PREFIX + getUDN())) {
                                existingList = someList.getId();
                                break;
                            }
                        }
                        saveQueue(ESH_PREFIX + getUDN(), existingList);
                        // get all the playlists and a ref to our
                        // saved list
                        playLists = getPlayLists();
                        for (SonosEntry someList : playLists) {
                            if (someList.getTitle().equals(ESH_PREFIX + getUDN())) {
                                savedState.entry = new SonosEntry(someList.getId(), someList.getTitle(), someList.getParentId(), "", "", "", someList.getUpnpClass(), someList.getRes());
                                break;
                            }
                        }
                    }
                } else {
                    savedState.entry = new SonosEntry("", "", "", "", "", "", "", QUEUE_URI + getUDN() + "#0");
                }
            }
            savedState.relTime = getPosition();
        } else {
            savedState.entry = null;
        }
    }
}
Also used : SonosMetaData(org.eclipse.smarthome.binding.sonos.internal.SonosMetaData) SonosZonePlayerState(org.eclipse.smarthome.binding.sonos.internal.SonosZonePlayerState) SonosEntry(org.eclipse.smarthome.binding.sonos.internal.SonosEntry) List(java.util.List) ArrayList(java.util.ArrayList)

Aggregations

SonosEntry (org.eclipse.smarthome.binding.sonos.internal.SonosEntry)9 StringType (org.eclipse.smarthome.core.library.types.StringType)5 ArrayList (java.util.ArrayList)2 SonosMetaData (org.eclipse.smarthome.binding.sonos.internal.SonosMetaData)2 List (java.util.List)1 SonosMusicService (org.eclipse.smarthome.binding.sonos.internal.SonosMusicService)1 SonosZoneGroup (org.eclipse.smarthome.binding.sonos.internal.SonosZoneGroup)1 SonosZonePlayerState (org.eclipse.smarthome.binding.sonos.internal.SonosZonePlayerState)1