mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
First attempt to display initial duration for audio attachements.
This commit is contained in:
@@ -78,6 +78,48 @@ public class AudioSlidePlayer implements SensorEventListener {
|
||||
}
|
||||
}
|
||||
|
||||
public void requestDuration() {
|
||||
if(this.mediaPlayer == null) {
|
||||
this.mediaPlayer = new MediaPlayerWrapper();
|
||||
try {
|
||||
this.audioAttachmentServer = new AttachmentServer(context, slide.asAttachment());
|
||||
this.startTime = System.currentTimeMillis();
|
||||
|
||||
audioAttachmentServer.start();
|
||||
this.mediaPlayer.setDataSource(context, audioAttachmentServer.getUri());
|
||||
|
||||
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
|
||||
@Override
|
||||
public void onPrepared(MediaPlayer mp) {
|
||||
Log.w(TAG, "onPrepared");
|
||||
synchronized (AudioSlidePlayer.this) {
|
||||
if (mediaPlayer == null) return;
|
||||
}
|
||||
getListener().onReceivedDuration(mediaPlayer.getDuration());
|
||||
if (mediaPlayer != null) {
|
||||
mediaPlayer.stop();
|
||||
mediaPlayer.release();
|
||||
}
|
||||
|
||||
if (audioAttachmentServer != null) {
|
||||
audioAttachmentServer.stop();
|
||||
}
|
||||
|
||||
mediaPlayer = null;
|
||||
audioAttachmentServer = null;
|
||||
}
|
||||
});
|
||||
mediaPlayer.prepareAsync();
|
||||
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, e);
|
||||
getListener().onReceivedDuration(0);
|
||||
}
|
||||
} else {
|
||||
getListener().onReceivedDuration(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void play(final double progress) throws IOException {
|
||||
play(progress, false);
|
||||
}
|
||||
@@ -256,6 +298,8 @@ public class AudioSlidePlayer implements SensorEventListener {
|
||||
public void onStop() {}
|
||||
@Override
|
||||
public void onProgress(double progress, long millis) {}
|
||||
@Override
|
||||
public void onReceivedDuration(long millis) {}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -321,6 +365,7 @@ public class AudioSlidePlayer implements SensorEventListener {
|
||||
public void onStart();
|
||||
public void onStop();
|
||||
public void onProgress(double progress, long millis);
|
||||
public void onReceivedDuration(long millis);
|
||||
}
|
||||
|
||||
private static class ProgressEventHandler extends Handler {
|
||||
|
||||
@@ -90,6 +90,7 @@ public class AudioView extends FrameLayout implements AudioSlidePlayer.Listener
|
||||
controlToggle.displayQuick(playButton);
|
||||
seekBar.setEnabled(true);
|
||||
this.audioSlidePlayer = AudioSlidePlayer.createFor(getContext(), audio, this);
|
||||
this.audioSlidePlayer.requestDuration();
|
||||
}
|
||||
|
||||
public void cleanup() {
|
||||
@@ -98,6 +99,13 @@ public class AudioView extends FrameLayout implements AudioSlidePlayer.Listener
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceivedDuration(long millis) {
|
||||
this.timestamp.setText(String.format("%02d:%02d",
|
||||
TimeUnit.MILLISECONDS.toMinutes(millis),
|
||||
TimeUnit.MILLISECONDS.toSeconds(millis)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
if (this.pauseButton.getVisibility() != View.VISIBLE) {
|
||||
|
||||
Reference in New Issue
Block a user