Skip to content
This repository was archived by the owner on Nov 4, 2018. It is now read-only.

Commit 938b41f

Browse files
committed
bugfix duration
1 parent 1535585 commit 938b41f

File tree

4 files changed

+33
-17
lines changed

4 files changed

+33
-17
lines changed

yaacc/src/de/yaacc/browser/ServerListActivity.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,11 @@ public void deviceUpdated(Device<?, ?, ?> device) {
133133
populateDeviceList();
134134
}
135135

136+
@Override
137+
public void onResume(){
138+
super.onResume();
139+
//refresh device list
140+
populateDeviceList();
141+
}
136142

137143
}

yaacc/src/de/yaacc/player/AbstractPlayer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ protected long getSilenceDuration() {
452452
* @param duration in millis
453453
*/
454454
public void startTimer(final long duration) {
455+
Log.d(getClass().getName(), "Start timer duration: " + duration);
455456
if (playerTimer != null) {
456457
cancelTimer();
457458
}

yaacc/src/de/yaacc/player/LocalBackgoundMusicPlayer.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -276,15 +276,24 @@ public URI getAlbumArt() {
276276
}
277277

278278
@SuppressLint("SimpleDateFormat")
279-
private String formatMillis(int millis) {
280-
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
281-
//next don't work with this line dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
282-
return dateFormat.format(new Date(millis));
283-
284-
/*int minutes = (int) Math.floor(millis / 1000 / 60);
285-
int seconds = (int) ((millis / 1000) - (minutes * 60));
286-
return "00:"+minutes + ":" + String.format("%02d", seconds);
287-
*/
279+
private String formatMillis(long millis) {
280+
281+
StringBuffer buf = new StringBuffer();
282+
283+
int hours = (int) (millis / (1000 * 60 * 60));
284+
int minutes = (int) ((millis % (1000 * 60 * 60)) / (1000 * 60));
285+
int seconds = (int) (((millis % (1000 * 60 * 60)) % (1000 * 60)) / 1000);
286+
287+
buf
288+
.append(String.format("%02d", hours))
289+
.append(":")
290+
.append(String.format("%02d", minutes))
291+
.append(":")
292+
.append(String.format("%02d", seconds));
293+
294+
return buf.toString();
295+
296+
288297
}
289298

290299
@Override

yaacc/src/de/yaacc/player/PlayableItem.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,16 +58,16 @@ public PlayableItem(Item item, int defaultDuration){
5858
setMimeType(mimeType);
5959

6060
// calculate duration
61-
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
62-
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
61+
6362
long millis = defaultDuration;
6463
if (resource.getDuration() != null) {
65-
try {
66-
Date date = dateFormat.parse(resource.getDuration());
67-
//millis = (date.getHours() * 3600 + date.getMinutes() * 60 + date.getSeconds()) * 1000;
68-
millis = date.getTime();
69-
Log.d(getClass().getName(), "Duration date object: " + date);
70-
} catch (ParseException e) {
64+
try{
65+
String[] tokens = resource.getDuration().split(":");
66+
millis = (Long.valueOf(tokens[0]) * 3600 + Long.valueOf(tokens[1]) * 60 + Long.valueOf(tokens[2])) * 1000;
67+
68+
Log.d(getClass().getName(), "resource.getDuration(): " + resource.getDuration() +" millis: " + millis);
69+
70+
} catch (Exception e) {
7171
Log.d(getClass().getName(), "bad duration format", e);
7272
}
7373
}

0 commit comments

Comments
 (0)