use of org.eclipse.smarthome.binding.sonos.internal.SonosEntry in project smarthome by eclipse.
the class ZonePlayerHandler method handleRadioStream.
/**
* Does a chain of predefined actions when a Notification sound is played by
* {@link ZonePlayerHandler#playNotificationSoundURI(Command)} in case
* radio streaming is currently loaded
*
* @param currentStreamURI - the currently loaded stream's URI
* @param notificationURL - the notification url in the format of //host/folder/filename.mp3
* @param coordinator - {@link ZonePlayerHandler} coordinator for the SONOS device(s)
*/
private void handleRadioStream(String currentStreamURI, Command notificationURL, ZonePlayerHandler coordinator) {
String nextAction = coordinator.getTransportState();
SonosMetaData track = coordinator.getTrackMetadata();
SonosMetaData currentURI = coordinator.getCurrentURIMetadata();
if (track != null && currentURI != null) {
handleNotificationSound(notificationURL, coordinator);
coordinator.setCurrentURI(new SonosEntry("", currentURI.getTitle(), "", "", track.getAlbumArtUri(), "", currentURI.getUpnpClass(), currentStreamURI));
restoreLastTransportState(coordinator, nextAction);
}
}
use of org.eclipse.smarthome.binding.sonos.internal.SonosEntry in project smarthome by eclipse.
the class ZonePlayerHandler method playFavorite.
/**
* This will attempt to match the station string with a entry in the
* favorites list, this supports both single entries and playlists
*
* @param favorite to match
* @return true if a match was found and played.
*/
public void playFavorite(Command command) {
if (command instanceof StringType) {
String favorite = command.toString();
List<SonosEntry> favorites = getFavorites();
SonosEntry theEntry = null;
// search for the appropriate favorite based on its name (title)
for (SonosEntry entry : favorites) {
if (entry.getTitle().equals(favorite)) {
theEntry = entry;
break;
}
}
// set the URI of the group coordinator
if (theEntry != null) {
try {
ZonePlayerHandler coordinator = getCoordinatorHandler();
/**
* If this is a playlist we need to treat it as such
*/
if (theEntry.getResourceMetaData() != null && theEntry.getResourceMetaData().getUpnpClass().startsWith("object.container")) {
coordinator.removeAllTracksFromQueue();
coordinator.addURIToQueue(theEntry);
coordinator.setCurrentURI(QUEUE_URI + coordinator.getUDN() + "#0", "");
String firstTrackNumberEnqueued = stateMap.get("FirstTrackNumberEnqueued");
if (firstTrackNumberEnqueued != null) {
coordinator.seek("TRACK_NR", firstTrackNumberEnqueued);
}
} else {
coordinator.setCurrentURI(theEntry);
}
coordinator.play();
} catch (IllegalStateException e) {
logger.debug("Cannot paly favorite ({})", e.getMessage());
}
} else {
logger.debug("Favorite '{}' not found", favorite);
}
}
}
use of org.eclipse.smarthome.binding.sonos.internal.SonosEntry in project smarthome by eclipse.
the class ZonePlayerHandler method playRadio.
public void playRadio(Command command) {
if (command instanceof StringType) {
String station = command.toString();
List<SonosEntry> stations = getFavoriteRadios();
SonosEntry theEntry = null;
// search for the appropriate radio based on its name (title)
for (SonosEntry someStation : stations) {
if (someStation.getTitle().equals(station)) {
theEntry = someStation;
break;
}
}
// set the URI of the group coordinator
if (theEntry != null) {
try {
ZonePlayerHandler coordinator = getCoordinatorHandler();
coordinator.setCurrentURI(theEntry);
coordinator.play();
} catch (IllegalStateException e) {
logger.debug("Cannot play radio ({})", e.getMessage());
}
} else {
logger.debug("Radio station '{}' not found", station);
}
}
}
use of org.eclipse.smarthome.binding.sonos.internal.SonosEntry in project smarthome by eclipse.
the class ZonePlayerHandler method removeMember.
public void removeMember(Command command) {
if (command != null && command instanceof StringType) {
try {
ZonePlayerHandler oldmemberHandler = getHandlerByName(command.toString());
oldmemberHandler.becomeStandAlonePlayer();
SonosEntry entry = new SonosEntry("", "", "", "", "", "", "", QUEUE_URI + oldmemberHandler.getUDN() + "#0");
oldmemberHandler.setCurrentURI(entry);
} catch (IllegalStateException e) {
logger.debug("Cannot remove group member ({})", e.getMessage());
}
}
}
use of org.eclipse.smarthome.binding.sonos.internal.SonosEntry in project smarthome by eclipse.
the class ZonePlayerHandler method publicAddress.
public boolean publicAddress() {
// check if sourcePlayer has a line-in connected
if (isAnalogLineInConnected() || isOpticalLineInConnected()) {
// first remove this player from its own group if any
becomeStandAlonePlayer();
List<SonosZoneGroup> currentSonosZoneGroups = new ArrayList<SonosZoneGroup>();
for (SonosZoneGroup grp : SonosXMLParser.getZoneGroupFromXML(stateMap.get("ZoneGroupState"))) {
currentSonosZoneGroups.add((SonosZoneGroup) grp.clone());
}
// add all other players to this new group
for (SonosZoneGroup group : currentSonosZoneGroups) {
for (String player : group.getMembers()) {
try {
ZonePlayerHandler somePlayer = getHandlerByName(player);
if (somePlayer != this) {
somePlayer.becomeStandAlonePlayer();
somePlayer.stop();
addMember(StringType.valueOf(somePlayer.getUDN()));
}
} catch (IllegalStateException e) {
logger.debug("Cannot add to group ({})", e.getMessage());
}
}
}
try {
ZonePlayerHandler coordinator = getCoordinatorHandler();
// set the URI of the group to the line-in
SonosEntry entry = new SonosEntry("", "", "", "", "", "", "", ANALOG_LINE_IN_URI + getUDN());
if (isOpticalLineInConnected()) {
entry = new SonosEntry("", "", "", "", "", "", "", OPTICAL_LINE_IN_URI + getUDN() + SPDIF);
}
coordinator.setCurrentURI(entry);
coordinator.play();
return true;
} catch (IllegalStateException e) {
logger.debug("Cannot handle command ({})", e.getMessage());
return false;
}
} else {
logger.debug("Line-in of {} is not connected", getUDN());
return false;
}
}
Aggregations