Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Commit

Permalink
Sonos binding: handle Google Play Music radio
Browse files Browse the repository at this point in the history
Fix #3937

Signed-off-by: Laurent Garnier <lg.hc@free.fr>
  • Loading branch information
lolodomo committed Aug 3, 2017
1 parent 0ab0579 commit 120bcf7
Showing 1 changed file with 31 additions and 4 deletions.
Expand Up @@ -85,6 +85,7 @@ public class ZonePlayerHandler extends BaseThingHandler implements UpnpIOPartici
private final static String QUEUE_URI = "x-rincon-queue:";
private final static String GROUP_URI = "x-rincon:";
private final static String STREAM_URI = "x-sonosapi-stream:";
private final static String RADIO_URI = "x-sonosapi-radio:";
private final static String FILE_URI = "x-file-cifs:";
private final static String SPDIF = ":spdif";

Expand Down Expand Up @@ -987,7 +988,9 @@ else if (isPlayingLineIn(currentURI)) {
}
}

else if (!currentURI.contains("x-rincon-mp3") && !currentURI.contains("x-sonosapi")) {
else if (isPlayingRadio(currentURI)
|| (!currentURI.contains("x-rincon-mp3") && !currentURI.contains("x-sonosapi"))) {
// isPlayingRadio(currentURI) is true for Google Play Music radio or Apple Music radio
if (currentTrack != null) {
artist = !currentTrack.getAlbumArtist().isEmpty() ? currentTrack.getAlbumArtist()
: currentTrack.getCreator();
Expand Down Expand Up @@ -1261,6 +1264,16 @@ protected void saveState() {
savedState.entry = new SonosEntry("", current.getTitle(), "", "", track.getAlbumArtUri(), "",
current.getUpnpClass(), currentURI);
}
} else if (isPlayingRadio(currentURI)) {
// we are playing radio (Goggle Play Music radio for example)
SonosMetaData track = getTrackMetadata();
SonosMetaData current = getCurrentURIMetadata();
if (track != null && current != null) {
savedState.entry = new SonosEntry("", track.getTitle(), "", track.getAlbum(),
track.getAlbumArtUri(),
!track.getAlbumArtist().isEmpty() ? track.getAlbumArtist() : track.getCreator(),
current.getUpnpClass(), currentURI);
}
} else if (currentURI.contains(GROUP_URI)) {
// we are a slave to some coordinator
savedState.entry = new SonosEntry("", "", "", "", "", "", "", currentURI);
Expand Down Expand Up @@ -2205,7 +2218,7 @@ public void playNotificationSoundURI(Command notificationURL) {

String currentURI = coordinator.getCurrentURI();

if (isPlayingStream(currentURI)) {
if (isPlayingStream(currentURI) || isPlayingRadio(currentURI)) {
handleRadioStream(currentURI, notificationURL, coordinator);
} else if (isPlayingLineIn(currentURI)) {
handleLineIn(currentURI, notificationURL, coordinator);
Expand Down Expand Up @@ -2242,6 +2255,13 @@ private boolean isPlayingStream(String currentURI) {
return currentURI.contains(STREAM_URI);
}

private boolean isPlayingRadio(String currentURI) {
if (currentURI == null) {
return false;
}
return currentURI.contains(RADIO_URI);
}

private boolean isPlayingLineIn(String currentURI) {
if (currentURI == null) {
return false;
Expand All @@ -2267,8 +2287,15 @@ private void handleRadioStream(String currentStreamURI, Command notificationURL,

if (track != null && currentURI != null) {
handleNotificationSound(notificationURL, coordinator);
coordinator.setCurrentURI(new SonosEntry("", currentURI.getTitle(), "", "", track.getAlbumArtUri(), "",
currentURI.getUpnpClass(), currentStreamURI));
if (isPlayingStream(currentStreamURI)) {
coordinator.setCurrentURI(new SonosEntry("", currentURI.getTitle(), "", "", track.getAlbumArtUri(), "",
currentURI.getUpnpClass(), currentStreamURI));
} else {
coordinator.setCurrentURI(
new SonosEntry("", track.getTitle(), "", track.getAlbum(), track.getAlbumArtUri(),
!track.getAlbumArtist().isEmpty() ? track.getAlbumArtist() : track.getCreator(),
currentURI.getUpnpClass(), currentStreamURI));
}

restoreLastTransportState(coordinator, nextAction);
}
Expand Down

0 comments on commit 120bcf7

Please sign in to comment.