diff options
author | Andrew Lee <anwlee@google.com> | 2015-06-12 21:24:23 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-06-12 21:24:28 +0000 |
commit | 477d4883cd6513ed95a4dfc1589d7ce3585a43fe (patch) | |
tree | d4c9c69fa2f2ebdc970cb1b1660a28e08b4c812b /src | |
parent | 0ec69a322aed252105b0768d38116706b0eedf95 (diff) | |
parent | bb4a4d4a9f9d0de739af34c023abeb200275ea43 (diff) |
Merge "Don't pass media player to VM playback layout." into mnc-dev
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/dialer/voicemail/VoicemailPlaybackLayout.java | 20 | ||||
-rw-r--r-- | src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java | 9 |
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); |