use of org.eclipse.smarthome.binding.sonos.internal.SonosZonePlayerState 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;
}
}
}
Aggregations