summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/com/android/dialer/voicemail/VoicemailPlaybackLayout.java20
-rw-r--r--src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java9
2 files changed, 14 insertions, 15 deletions
diff --git a/src/com/android/dialer/voicemail/VoicemailPlaybackLayout.java b/src/com/android/dialer/voicemail/VoicemailPlaybackLayout.java
index 0313f4004..73f4b3b1c 100644
--- a/src/com/android/dialer/voicemail/VoicemailPlaybackLayout.java
+++ b/src/com/android/dialer/voicemail/VoicemailPlaybackLayout.java
@@ -69,17 +69,13 @@ public class VoicemailPlaybackLayout extends LinearLayout
/** Update rate for the slider, 30fps. */
private static final int SLIDER_UPDATE_PERIOD_MILLIS = 1000 / 30;
- private final MediaPlayer mMediaPlayer;
- private final int mDuration;
+ private int mDuration;
private final ScheduledExecutorService mExecutorService;
private final Object mLock = new Object();
@GuardedBy("mLock") private ScheduledFuture<?> mScheduledFuture;
- public PositionUpdater(
- MediaPlayer mediaPlayer,
- ScheduledExecutorService executorService) {
- mMediaPlayer = mediaPlayer;
- mDuration = mediaPlayer.getDuration();
+ public PositionUpdater(int duration, ScheduledExecutorService executorService) {
+ mDuration = duration;
mExecutorService = executorService;
}
@@ -90,11 +86,11 @@ public class VoicemailPlaybackLayout extends LinearLayout
public void run() {
int currentPosition = 0;
synchronized (mLock) {
- if (mScheduledFuture == null) {
+ if (mScheduledFuture == null || mPresenter == null) {
// This task has been canceled. Just stop now.
return;
}
- currentPosition = mMediaPlayer.getCurrentPosition();
+ currentPosition = mPresenter.getMediaPlayerPosition();
}
setClipPosition(currentPosition, mDuration);
}
@@ -234,9 +230,7 @@ public class VoicemailPlaybackLayout extends LinearLayout
}
@Override
- public void onPlaybackStarted(
- MediaPlayer mediaPlayer,
- ScheduledExecutorService executorService) {
+ public void onPlaybackStarted(int duration, ScheduledExecutorService executorService) {
mIsPlaying = true;
mStartStopButton.setImageResource(R.drawable.ic_hold_pause);
@@ -245,7 +239,7 @@ public class VoicemailPlaybackLayout extends LinearLayout
onSpeakerphoneOn(mPresenter.isSpeakerphoneOn());
}
- mPositionUpdater = new PositionUpdater(mediaPlayer, executorService);
+ mPositionUpdater = new PositionUpdater(duration, executorService);
mPositionUpdater.startUpdating();
}
diff --git a/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java b/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java
index 5b4478f53..d47e9e213 100644
--- a/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java
+++ b/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java
@@ -78,7 +78,7 @@ public class VoicemailPlaybackPresenter
void disableUiElements();
void enableUiElements();
void onPlaybackError(Exception e);
- void onPlaybackStarted(MediaPlayer mediaPlayer, ScheduledExecutorService executorService);
+ void onPlaybackStarted(int duration, ScheduledExecutorService executorService);
void onPlaybackStopped();
void onSpeakerphoneOn(boolean on);
void setClipPosition(int clipPositionInMillis, int clipLengthInMillis);
@@ -197,6 +197,7 @@ public class VoicemailPlaybackPresenter
} else {
mVoicemailUri = voicemailUri;
mPosition = 0;
+ mDuration.set(0);
mIsPlaying = startPlayingImmediately;
// Default to earpiece.
@@ -498,7 +499,7 @@ public class VoicemailPlaybackPresenter
}
enableProximitySensor();
- mView.onPlaybackStarted(mMediaPlayer, getScheduledExecutorServiceInstance());
+ mView.onPlaybackStarted(mDuration.get(), getScheduledExecutorServiceInstance());
}
/**
@@ -584,6 +585,10 @@ public class VoicemailPlaybackPresenter
return mVoicemailUri;
}
+ public int getMediaPlayerPosition() {
+ return mIsPrepared ? mMediaPlayer.getCurrentPosition() : 0;
+ }
+
private static synchronized ScheduledExecutorService getScheduledExecutorServiceInstance() {
if (mScheduledExecutorService == null) {
mScheduledExecutorService = Executors.newScheduledThreadPool(NUMBER_OF_THREADS_IN_POOL);