Merge remote-tracking branch 'origin/pr/1355'

master
Andrew DeMaria 5 years ago
commit 546451bf0a
No known key found for this signature in database
GPG Key ID: 0A3F5E91F8364EDF
  1. 2
      airsonic-main/src/main/java/org/airsonic/player/ajax/PlayQueueInfo.java
  2. 2
      airsonic-main/src/main/java/org/airsonic/player/controller/VideoPlayerController.java
  3. 28
      airsonic-main/src/main/java/org/airsonic/player/domain/MediaFile.java
  4. 2
      airsonic-main/src/main/java/org/airsonic/player/domain/Playlist.java
  5. 22
      airsonic-main/src/main/java/org/airsonic/player/service/upnp/CustomContentDirectory.java
  6. 34
      airsonic-main/src/main/java/org/airsonic/player/util/StringUtil.java
  7. 31
      airsonic-main/src/test/java/org/airsonic/player/util/StringUtilTestCase.java

@ -61,7 +61,7 @@ public class PlayQueueInfo {
durationSeconds += entry.getDuration(); durationSeconds += entry.getDuration();
} }
} }
return StringUtil.formatDuration(durationSeconds); return StringUtil.formatDurationMSS(durationSeconds);
} }
public boolean isStopEnabled() { public boolean isStopEnabled() {

@ -89,7 +89,7 @@ public class VideoPlayerController {
public static Map<String, Integer> createSkipOffsets(int durationSeconds) { public static Map<String, Integer> createSkipOffsets(int durationSeconds) {
LinkedHashMap<String, Integer> result = new LinkedHashMap<String, Integer>(); LinkedHashMap<String, Integer> result = new LinkedHashMap<String, Integer>();
for (int i = 0; i < durationSeconds; i += 60) { for (int i = 0; i < durationSeconds; i += 60) {
result.put(StringUtil.formatDuration(i), i); result.put(StringUtil.formatDurationMSS(i), i);
} }
return result; return result;
} }

@ -22,6 +22,7 @@ package org.airsonic.player.domain;
import com.google.common.base.Function; import com.google.common.base.Function;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import org.airsonic.player.util.FileUtil; import org.airsonic.player.util.FileUtil;
import org.airsonic.player.util.StringUtil;
import org.apache.commons.io.FilenameUtils; import org.apache.commons.io.FilenameUtils;
import java.io.File; import java.io.File;
@ -279,31 +280,8 @@ public class MediaFile {
if (durationSeconds == null) { if (durationSeconds == null) {
return null; return null;
} }
// Return in M:SS or H:MM:SS
StringBuilder result = new StringBuilder(8); return StringUtil.formatDuration(durationSeconds);
int seconds = durationSeconds;
int hours = seconds / 3600;
seconds -= hours * 3600;
int minutes = seconds / 60;
seconds -= minutes * 60;
if (hours > 0) {
result.append(hours).append(':');
if (minutes < 10) {
result.append('0');
}
}
result.append(minutes).append(':');
if (seconds < 10) {
result.append('0');
}
result.append(seconds);
return result.toString();
} }
public Long getFileSize() { public Long getFileSize() {

@ -113,7 +113,7 @@ public class Playlist {
} }
public String getDurationAsString() { public String getDurationAsString() {
return StringUtil.formatDuration(durationSeconds); return StringUtil.formatDurationMSS(durationSeconds);
} }
public Date getCreated() { public Date getCreated() {

@ -89,27 +89,7 @@ public abstract class CustomContentDirectory extends AbstractContentDirectorySer
if (seconds == null) { if (seconds == null) {
return null; return null;
} }
return StringUtil.formatDurationHMMSS((int)seconds) + ".0";
StringBuilder result = new StringBuilder(8);
int hours = seconds / 3600;
seconds -= hours * 3600;
int minutes = seconds / 60;
seconds -= minutes * 60;
result.append(hours).append(':');
if (minutes < 10) {
result.append('0');
}
result.append(minutes).append(':');
if (seconds < 10) {
result.append('0');
}
result.append(seconds);
result.append(".0");
return result.toString();
} }
protected String getBaseUrl() { protected String getBaseUrl() {

@ -226,19 +226,33 @@ public final class StringUtil {
} }
/** /**
* Formats a duration with minutes and seconds, e.g., "93:45" * Formats a duration with minutes and seconds, e.g., "4:34" or "93:45"
*/ */
public static String formatDuration(int seconds) { public static String formatDurationMSS(int seconds) {
int minutes = seconds / 60; if (seconds < 0) {
int secs = seconds % 60; throw new IllegalArgumentException("seconds must be >= 0");
}
return String.format("%d:%02d", seconds / 60, seconds % 60);
}
/**
* Formats a duration with H:MM:SS, e.g., "1:33:45"
*/
public static String formatDurationHMMSS(int seconds) {
int hours = seconds / 3600;
seconds -= hours * 3600;
StringBuilder builder = new StringBuilder(6); return String.format("%d:%s%s", hours, seconds < 600 ? "0" : "", formatDurationMSS(seconds));
builder.append(minutes).append(":"); }
if (secs < 10) {
builder.append("0"); /**
* Formats a duration to M:SS or H:MM:SS
*/
public static String formatDuration(int seconds) {
if (seconds >= 3600) {
return formatDurationHMMSS(seconds);
} }
builder.append(secs); return formatDurationMSS(seconds);
return builder.toString();
} }
/** /**

@ -81,6 +81,34 @@ public class StringUtilTestCase extends TestCase {
assertEquals("Error in formatBytes().", "4413,43 TB", StringUtil.formatBytes(4852617603375432L, locale)); assertEquals("Error in formatBytes().", "4413,43 TB", StringUtil.formatBytes(4852617603375432L, locale));
} }
public void testFormatDurationMSS() {
assertEquals("Error in formatDurationMSS().", "0:00", StringUtil.formatDurationMSS(0));
assertEquals("Error in formatDurationMSS().", "0:05", StringUtil.formatDurationMSS(5));
assertEquals("Error in formatDurationMSS().", "0:10", StringUtil.formatDurationMSS(10));
assertEquals("Error in formatDurationMSS().", "0:59", StringUtil.formatDurationMSS(59));
assertEquals("Error in formatDurationMSS().", "1:00", StringUtil.formatDurationMSS(60));
assertEquals("Error in formatDurationMSS().", "1:01", StringUtil.formatDurationMSS(61));
assertEquals("Error in formatDurationMSS().", "1:10", StringUtil.formatDurationMSS(70));
assertEquals("Error in formatDurationMSS().", "10:00", StringUtil.formatDurationMSS(600));
assertEquals("Error in formatDurationMSS().", "45:50", StringUtil.formatDurationMSS(2750));
assertEquals("Error in formatDurationMSS().", "83:45", StringUtil.formatDurationMSS(5025));
assertEquals("Error in formatDurationMSS().", "121:40", StringUtil.formatDurationMSS(7300));
}
public void testFormatDurationHMMSS() {
assertEquals("Error in formatDurationHMMSS().", "0:00:00", StringUtil.formatDurationHMMSS(0));
assertEquals("Error in formatDurationHMMSS().", "0:00:05", StringUtil.formatDurationHMMSS(5));
assertEquals("Error in formatDurationHMMSS().", "0:00:10", StringUtil.formatDurationHMMSS(10));
assertEquals("Error in formatDurationHMMSS().", "0:00:59", StringUtil.formatDurationHMMSS(59));
assertEquals("Error in formatDurationHMMSS().", "0:01:00", StringUtil.formatDurationHMMSS(60));
assertEquals("Error in formatDurationHMMSS().", "0:01:01", StringUtil.formatDurationHMMSS(61));
assertEquals("Error in formatDurationHMMSS().", "0:01:10", StringUtil.formatDurationHMMSS(70));
assertEquals("Error in formatDurationHMMSS().", "0:10:00", StringUtil.formatDurationHMMSS(600));
assertEquals("Error in formatDurationHMMSS().", "0:45:50", StringUtil.formatDurationHMMSS(2750));
assertEquals("Error in formatDurationHMMSS().", "1:23:45", StringUtil.formatDurationHMMSS(5025));
assertEquals("Error in formatDurationHMMSS().", "2:01:40", StringUtil.formatDurationHMMSS(7300));
}
public void testFormatDuration() { public void testFormatDuration() {
assertEquals("Error in formatDuration().", "0:00", StringUtil.formatDuration(0)); assertEquals("Error in formatDuration().", "0:00", StringUtil.formatDuration(0));
assertEquals("Error in formatDuration().", "0:05", StringUtil.formatDuration(5)); assertEquals("Error in formatDuration().", "0:05", StringUtil.formatDuration(5));
@ -91,7 +119,8 @@ public class StringUtilTestCase extends TestCase {
assertEquals("Error in formatDuration().", "1:10", StringUtil.formatDuration(70)); assertEquals("Error in formatDuration().", "1:10", StringUtil.formatDuration(70));
assertEquals("Error in formatDuration().", "10:00", StringUtil.formatDuration(600)); assertEquals("Error in formatDuration().", "10:00", StringUtil.formatDuration(600));
assertEquals("Error in formatDuration().", "45:50", StringUtil.formatDuration(2750)); assertEquals("Error in formatDuration().", "45:50", StringUtil.formatDuration(2750));
assertEquals("Error in formatDuration().", "83:45", StringUtil.formatDuration(5025)); assertEquals("Error in formatDuration().", "1:23:45", StringUtil.formatDuration(5025));
assertEquals("Error in formatDuration().", "2:01:40", StringUtil.formatDuration(7300));
} }
public void testSplit() { public void testSplit() {

Loading…
Cancel
Save