aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart
diff options
context:
space:
mode:
authorChristian Schneppe <christian.schneppe@pix-art.de>2019-11-14 20:52:59 +0100
committerChristian Schneppe <christian.schneppe@pix-art.de>2019-11-15 17:14:10 +0100
commit25babd117d0efed2ad09cb8f5f465abdf5ae6ed0 (patch)
tree99b91bbc3e393ac2a991b358961b3f3b362d2e9e /src/main/java/de/pixart
parent88948711ff79b9fe7f7ff9badc1b08a97209143f (diff)
do not crash when audio file reports zero length
Diffstat (limited to 'src/main/java/de/pixart')
-rw-r--r--src/main/java/de/pixart/messenger/services/AudioPlayer.java15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/main/java/de/pixart/messenger/services/AudioPlayer.java b/src/main/java/de/pixart/messenger/services/AudioPlayer.java
index ecb3f5c21..501c6b9a5 100644
--- a/src/main/java/de/pixart/messenger/services/AudioPlayer.java
+++ b/src/main/java/de/pixart/messenger/services/AudioPlayer.java
@@ -12,8 +12,6 @@ import android.media.AudioManager;
import android.os.Build;
import android.os.Handler;
import android.os.PowerManager;
-import androidx.core.app.ActivityCompat;
-import androidx.core.content.ContextCompat;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
@@ -21,6 +19,9 @@ import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.TextView;
+import androidx.core.app.ActivityCompat;
+import androidx.core.content.ContextCompat;
+
import java.lang.ref.WeakReference;
import java.util.Locale;
import java.util.concurrent.ExecutorService;
@@ -89,7 +90,7 @@ public class AudioPlayer implements View.OnClickListener, MediaPlayer.OnCompleti
audioPlayer.setTag(message);
if (init(ViewHolder.get(audioPlayer), message)) {
this.audioPlayerLayouts.addWeakReferenceTo(audioPlayer);
- executor.execute(()-> this.stopRefresher(true));
+ executor.execute(() -> this.stopRefresher(true));
} else {
this.audioPlayerLayouts.removeWeakReferenceTo(audioPlayer);
}
@@ -343,8 +344,12 @@ public class AudioPlayer implements View.OnClickListener, MediaPlayer.OnCompleti
return false;
}
final ViewHolder viewHolder = ViewHolder.get(audioPlayer);
- viewHolder.progress.setProgress(current * 100 / duration);
- viewHolder.runtime.setText(formatTime(current) + " / " + formatTime(duration));
+ if (duration <= 0) {
+ viewHolder.progress.setProgress(100);
+ } else {
+ viewHolder.progress.setProgress(current * 100 / duration);
+ }
+ viewHolder.runtime.setText(String.format("%s / %s", formatTime(current), formatTime(duration)));
return true;
}