Skip to content

Commit

Permalink
Implementation of the playTrack functionality
Browse files Browse the repository at this point in the history
Signed-off-by: Karel Goderis <[email protected]>
  • Loading branch information
kgoderis committed Feb 20, 2015
1 parent 195f846 commit 491f7f2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
<channel id="playlinein" typeId="playlinein" />
<channel id="playlist" typeId="playlist" />
<channel id="playqueue" typeId="playqueue" />
<channel id="playtrack" typeId="playtrack" />
<channel id="playuri" typeId="playuri" />
<channel id="publicaddress" typeId="publicaddress" />
<channel id="radio" typeId="radio" />
Expand Down Expand Up @@ -156,7 +157,12 @@
<label>Play Queue</label>
<description>Play the songs from the current queue</description>
</channel-type>


<channel-type id="playtrack" advanced="true">
<item-type>Number</item-type>
<label>Play Track</label>
<description>Play the given track number from the current queue</description>
</channel-type>

<channel-type id="playuri" advanced="true">
<item-type>String</item-type>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class SonosBindingConstants {
public final static String PLAYLINEIN = "playlinein";
public final static String PLAYLIST = "playlist";
public final static String PLAYQUEUE = "playqueue";
public final static String PLAYTRACK = "playtrack";
public final static String PLAYURI = "playuri";
public final static String PUBLICADDRESS = "publicaddress";
public final static String RADIO = "radio";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,9 @@ public void handleCommand(ChannelUID channelUID, Command command) {
case PLAYQUEUE:
playQueue(command);
break;
case PLAYTRACK:
playTrack(command);
break;
case PLAYURI:
playURI(command);
break;
Expand Down Expand Up @@ -656,7 +659,7 @@ protected void updateCurrentURIFormatted(String URI) {
// currentURI = getCurrentURI();
currentTrack = getTrackMetadata();
}

if (currentURI != null) {
String title = stateMap.get("CurrentTitle");
String resultString = stateMap.get("CurrentURIFormatted");
Expand Down Expand Up @@ -1207,6 +1210,10 @@ public void setPosition(String relTime) {
public void setPositionTrack(long tracknr) {
seek("TRACK_NR", Long.toString(tracknr));
}

public void setPositionTrack(String tracknr) {
seek("TRACK_NR", tracknr);
}

protected void seek(String unit, String target) {
if (unit != null && target != null) {
Expand Down Expand Up @@ -1641,7 +1648,7 @@ public void playURI(Command command) {
}

}

public void playQueue(Command command) {
ZonePlayerHandler coordinator = getHandlerByName(getCoordinator());

Expand Down Expand Up @@ -1739,6 +1746,25 @@ public void playRadio(Command command) {

}

public void playTrack(Command command) {

if(command != null && command instanceof DecimalType) {
ZonePlayerHandler coordinator = getHandlerByName(getCoordinator());

String trackNumber = command.toString();

// seek the track - warning, we do not check if the tracknumber falls in the boundary of the queue
setPositionTrack(trackNumber);

// take the system off mute
coordinator.setMute(OnOffType.OFF);

// start jammin'
coordinator.play();
}

}

public void playPlayList(Command command) {
List<SonosEntry> playlists = getPlayLists();
SonosEntry theEntry = null;
Expand Down

0 comments on commit 491f7f2

Please sign in to comment.