From e5fc3ebd9caeafff374f2c35665a5b941455b8bd Mon Sep 17 00:00:00 2001 From: Karel Goderis Date: Fri, 20 Feb 2015 20:37:30 +0100 Subject: [PATCH] Further improvement of Metadata methods Signed-off-by: Karel Goderis --- .../sonos/handler/ZonePlayerHandler.java | 41 +++++++++++++------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/addons/binding/org.openhab.binding.sonos/src/main/java/org/openhab/binding/sonos/handler/ZonePlayerHandler.java b/addons/binding/org.openhab.binding.sonos/src/main/java/org/openhab/binding/sonos/handler/ZonePlayerHandler.java index f2aa92eb3371b..eb4015551362d 100644 --- a/addons/binding/org.openhab.binding.sonos/src/main/java/org/openhab/binding/sonos/handler/ZonePlayerHandler.java +++ b/addons/binding/org.openhab.binding.sonos/src/main/java/org/openhab/binding/sonos/handler/ZonePlayerHandler.java @@ -456,7 +456,7 @@ public void onValueReceived(String variable, String value, String service) { break; } case "CurrentURI": { - updateCurrentURIFormatted(); + updateCurrentURIFormatted(value); break; } } @@ -596,8 +596,15 @@ public boolean isCoordinator() { protected void updateTrackMetaData() { + String coordinator = getCoordinator(); + ZonePlayerHandler coordinatorHandler = getHandlerByName(coordinator); SonosMetaData currentTrack = getTrackMetadata(); + if (coordinatorHandler != null && coordinatorHandler != this) { + coordinatorHandler.updateMediaInfo(); + currentTrack = coordinatorHandler.getTrackMetadata(); + } + if (currentTrack != null) { String artist = null; @@ -623,38 +630,36 @@ protected void updateTrackMetaData() { this.onValueReceived("CurrentAlbum", (album != null) ? album : "", "AVTransport"); - if(currentTrack.getTitle().contains("x-sonosapi-stream")) { - updateMediaInfo(); - } + updateMediaInfo(); + } } - protected void updateCurrentURIFormatted() { + protected void updateCurrentURIFormatted(String URI) { - String currentURI = null; + String currentURI = URI; SonosMetaData currentTrack = null; String coordinator = getCoordinator(); ZonePlayerHandler coordinatorHandler = getHandlerByName(coordinator); if (coordinatorHandler != null && coordinatorHandler != this) { - if(getCurrentURI().contains("x-rincon")) { + if(currentURI.contains("x-rincon-stream")) { coordinatorHandler.updateMediaInfo(); } currentURI = coordinatorHandler.getCurrentURI(); currentTrack = coordinatorHandler.getTrackMetadata(); } else { - currentURI = getCurrentURI(); + // currentURI = getCurrentURI(); currentTrack = getTrackMetadata(); } - + if (currentURI != null) { String title = stateMap.get("CurrentTitle"); String resultString = stateMap.get("CurrentURIFormatted"); boolean needsUpdating = false; if (opmlPartnerID != null && currentURI.contains("x-sonosapi-stream")) { - String stationID = StringUtils.substringBetween(currentURI, ":s", "?sid"); String previousStationID = stateMap.get("StationID"); @@ -706,9 +711,18 @@ protected void updateCurrentURIFormatted() { } } } - } else { + } + + if(currentURI.contains("x-rincon-stream")) { + if(currentTrack != null) { + resultString = stateMap.get("CurrentTitle"); + needsUpdating = true; + } + } - if (currentTrack != null && !currentTrack.getTitle().contains("x-sonosapi-stream")) { + + if (!currentURI.contains("x-rincon-mp3") && !currentURI.contains("x-rincon-stream") && !currentURI.contains("x-sonosapi")) { + if(currentTrack != null) { if (currentTrack.getAlbumArtist().equals("")) { resultString = currentTrack.getCreator() + " - " + currentTrack.getAlbum() + " - " @@ -723,6 +737,7 @@ protected void updateCurrentURIFormatted() { } } + if(needsUpdating) { this.onValueReceived("CurrentURIFormatted", (resultString != null) ? resultString : "", "AVTransport"); @@ -1776,7 +1791,7 @@ public String getCurrentZoneName() { } public String getCurrentURIFormatted() { - updateCurrentURIFormatted(); + updateCurrentURIFormatted(getCurrentURI()); return stateMap.get("CurrentURIFormatted"); }