1 package util
.response
.ctrlint
;
3 import interfaces
.Constants
;
18 * playlist position id
30 public class PlayStatusUpdate
extends Response
{
33 public final int revision
;
34 public final Status state
;
37 * false: no shuffle, true: shuffle
39 public final boolean shuffle
;
44 * 2: repeat (playlist)
46 public final int repeat
;
48 public PlayStatusUpdate(int revision
, boolean shuffle
, int repeat
) {
49 super(Constants
.dmcp_status
, Response
.OK
);
50 this.revision
= revision
;
51 this.state
= Status
.STOPPED
;
52 this.shuffle
= shuffle
;
56 protected PlayStatusUpdate(int revision
, Status state
, boolean shuffle
, int repeat
) {
57 super(Constants
.dmcp_status
, Response
.OK
);
58 this.revision
= revision
;
60 this.shuffle
= shuffle
;
64 public static PlayStatusUpdate
read(Reader reader
) {
67 Status state
= Status
.STOPPED
;
68 boolean shuffle
= false;
70 int currentDatabase
= 0;
71 int currentPlaylist
= 0;
72 int currentPlaylistTrack
= 0;
74 String trackTitle
= null;
75 String trackArtist
= null;
76 String trackAlbum
= null;
77 String trackGenre
= null;
78 long currentAlbumId
= 0;
80 int remainingTime
= 0;
83 for (Constants code
: reader
) {
86 case dmcp_mediarevision
:
87 revision
= reader
.nextInteger(code
);
90 state
= status(reader
.nextByte(code
));
93 shuffle
= reader
.nextBoolean(code
);
96 repeat
= reader
.nextByte(code
);
99 int[] canp
= reader
.nextLongLong(code
);
100 currentDatabase
= canp
[0];
101 currentPlaylist
= canp
[1];
102 currentPlaylistTrack
= canp
[2];
103 currentTrack
= canp
[3];
105 case dacp_nowplayingname
:
106 trackTitle
= reader
.nextString(code
);
108 case dacp_nowplayingartist
:
109 trackArtist
= reader
.nextString(code
);
111 case dacp_nowplayingalbum
:
112 trackAlbum
= reader
.nextString(code
);
114 case dacp_nowplayinggenre
:
115 trackGenre
= reader
.nextString(code
);
117 case daap_songalbumid
:
118 currentAlbumId
= reader
.nextLong(code
);
120 case dacp_remainingtime
:
121 remainingTime
= reader
.nextInteger(code
);
124 totalTime
= reader
.nextInteger(code
);
129 if (state
== Status
.STOPPED
) {
130 return new PlayStatusUpdate(revision
, shuffle
, repeat
);
133 return new Active(revision
, state
, shuffle
, repeat
,
134 currentDatabase
, currentPlaylist
, currentPlaylistTrack
, currentTrack
,
135 trackTitle
, trackArtist
, trackAlbum
, trackGenre
, currentAlbumId
,
136 mediaKind
, remainingTime
, totalTime
);
140 public Constants
type() {
141 return Constants
.dmcp_status
;
144 public void write(Writer writer
) {
146 writer
.appendInteger(Constants
.dmcp_mediarevision
, revision
);
147 writer
.appendByte(Constants
.dacp_state
, state
.value());
148 writer
.appendBoolean(Constants
.dacp_shuffle
, shuffle
);
149 writer
.appendByte(Constants
.dacp_repeat
, (byte)repeat
);
150 writer
.appendInteger(Constants
.dacp_albumshuffle
, 2);
151 writer
.appendInteger(Constants
.dacp_albumrepeat
, 6);
155 public String
toString() {
156 return revision
+ ": stopped";
159 public static final Status
status(byte status
) {
161 case 2: return Status
.STOPPED
;
162 case 3: return Status
.PAUSED
;
163 case 4: return Status
.PLAYING
;
168 public Active
active() {
180 public byte value() {
195 * playlist position id
207 public static class Active
extends PlayStatusUpdate
{
209 public final int currentDatabase
;
210 public final int currentPlaylist
;
211 public final int currentPosition
;
212 public final int currentTrackId
;
214 public final String trackTitle
;
215 public final String trackArtist
;
216 public final String trackAlbum
;
217 public final String trackGenre
;
219 public final long currentAlbumId
;
220 public final int mediaKind
;
221 public final int remainingTime
;
222 public final int totalTime
;
224 public Active(int revision
, Status state
, boolean shuffle
,
225 int repeat
, int currentDatabase
, int currentPlaylist
,
226 int currentPosition
, int currentTrackId
, String trackTitle
,
227 String trackArtist
, String trackAlbum
, String trackGenre
,
228 long currentAlbumId
, int mediaKind
, int remainingTime
, int totalTime
) {
230 super(revision
, state
, shuffle
, repeat
);
232 this.currentDatabase
= currentDatabase
;
233 this.currentPlaylist
= currentPlaylist
;
234 this.currentPosition
= currentPosition
;
235 this.currentTrackId
= currentTrackId
;
236 this.trackTitle
= trackTitle
;
237 this.trackArtist
= trackArtist
;
238 this.trackAlbum
= trackAlbum
;
239 this.trackGenre
= trackGenre
;
240 this.currentAlbumId
= currentAlbumId
;
241 this.mediaKind
= mediaKind
;
242 this.remainingTime
= remainingTime
;
243 this.totalTime
= totalTime
;
246 public void write(Writer writer
) {
249 writer
.appendLongLong(Constants
.dacp_nowplaying
, new int[] {
255 writer
.appendString(Constants
.dacp_nowplayingname
, trackTitle
);
256 writer
.appendString(Constants
.dacp_nowplayingartist
, trackArtist
);
257 writer
.appendString(Constants
.dacp_nowplayingalbum
, trackAlbum
);
258 writer
.appendString(Constants
.dacp_nowplayinggenre
, trackGenre
);
259 writer
.appendLong(Constants
.daap_songalbumid
, currentAlbumId
);
260 writer
.appendInteger(Constants
.dmcp_mediakind
, 1); //media kind - only support songs
261 writer
.appendInteger(Constants
.dacp_remainingtime
, remainingTime
);
262 writer
.appendInteger(Constants
.dacp_songtime
, totalTime
);
265 public Active
active() {
269 public String
toString() {
270 return this.revision
+ ": " + trackTitle
+ " - " + trackArtist
;