add a time conversion class

convert time depending on current playback speed and preferences
This commit is contained in:
Cédric Cabessa 2019-03-03 18:35:52 +01:00
parent 743ec1927c
commit 6187945e8f
1 changed files with 22 additions and 0 deletions

View File

@ -0,0 +1,22 @@
package de.danoeh.antennapod.core.util;
import de.danoeh.antennapod.core.preferences.UserPreferences;
public class TimeSpeedConverter {
private TimeSpeedConverter() {
}
/** Convert millisecond according to the current playback speed
* @param time: time to convert
* @return converted time (can be < 0 if time is < 0)
*/
public static int convert(int time) {
boolean timeRespectsSpeed = UserPreferences.timeRespectsSpeed();
if (time > 0 && timeRespectsSpeed) {
float speed = Float.parseFloat(UserPreferences.getPlaybackSpeed());
return (int)(time / speed);
}
return time;
}
}