fix audio player time display + progress for long audio files
This commit is contained in:
parent
c06f2d23f6
commit
3a489741e7
|
@ -22,6 +22,8 @@ import android.widget.TextView;
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
|
|
||||||
|
import com.google.common.primitives.Ints;
|
||||||
|
|
||||||
import eu.siacs.conversations.Config;
|
import eu.siacs.conversations.Config;
|
||||||
import eu.siacs.conversations.R;
|
import eu.siacs.conversations.R;
|
||||||
import eu.siacs.conversations.entities.Message;
|
import eu.siacs.conversations.entities.Message;
|
||||||
|
@ -29,10 +31,10 @@ import eu.siacs.conversations.services.MediaPlayer;
|
||||||
import eu.siacs.conversations.ui.ConversationsActivity;
|
import eu.siacs.conversations.ui.ConversationsActivity;
|
||||||
import eu.siacs.conversations.ui.adapter.MessageAdapter;
|
import eu.siacs.conversations.ui.adapter.MessageAdapter;
|
||||||
import eu.siacs.conversations.ui.util.PendingItem;
|
import eu.siacs.conversations.ui.util.PendingItem;
|
||||||
|
import eu.siacs.conversations.utils.TimeFrameUtils;
|
||||||
import eu.siacs.conversations.utils.WeakReferenceSet;
|
import eu.siacs.conversations.utils.WeakReferenceSet;
|
||||||
|
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.Locale;
|
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
|
@ -78,12 +80,8 @@ public class AudioPlayer
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String formatTime(int ms) {
|
private static String formatTime(final int ms) {
|
||||||
return String.format(
|
return TimeFrameUtils.formatElapsedTime(ms,false);
|
||||||
Locale.ENGLISH,
|
|
||||||
"%d:%02d",
|
|
||||||
ms / 60000,
|
|
||||||
Math.min(Math.round((ms % 60000) / 1000f), 59));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initializeProximityWakeLock(Context context) {
|
private void initializeProximityWakeLock(Context context) {
|
||||||
|
@ -383,7 +381,8 @@ public class AudioPlayer
|
||||||
if (duration <= 0) {
|
if (duration <= 0) {
|
||||||
viewHolder.progress.setProgress(100);
|
viewHolder.progress.setProgress(100);
|
||||||
} else {
|
} else {
|
||||||
viewHolder.progress.setProgress(current * 100 / duration);
|
final var progress = current * 100L / duration;
|
||||||
|
viewHolder.progress.setProgress(Math.min(Ints.saturatedCast(progress), 100));
|
||||||
}
|
}
|
||||||
viewHolder.runtime.setText(
|
viewHolder.runtime.setText(
|
||||||
String.format("%s / %s", formatTime(current), formatTime(duration)));
|
String.format("%s / %s", formatTime(current), formatTime(duration)));
|
||||||
|
|
Loading…
Reference in a new issue