diff options
author | Andrew Lee <anwlee@google.com> | 2015-05-29 10:39:14 -0700 |
---|---|---|
committer | Andrew Lee <anwlee@google.com> | 2015-06-01 11:50:09 -0700 |
commit | 42be85d8a976c049ea237a48a35beada80638b85 (patch) | |
tree | 975b86d8b44691c1bd29f0055102932ae676c17c /src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java | |
parent | 6c327dcc027c6df1548873031d62a0d84a0dc50d (diff) |
Fix CallDetailActivity tests.
+ Reset the AsyncTaskExecutor's instance between calls in tests.
I don't know why this is necessary, but it fixes a class of problems
which were happening.
+ Don't try to release a media player if it has not been prepared.
+ Handle possible race conditions since MediaPlayer's async prepare
may be buffering or finished when a test assert is executed.
+ Add asset file no longer provided by variablespeed library.
- Cleanup some stream copy code.
Change-Id: I0ae5fde00514c6dcdb1e9c063435a13eed6e8528
Diffstat (limited to 'src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java')
-rw-r--r-- | src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java b/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java index 1ab87fd24..1ee376582 100644 --- a/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java +++ b/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java @@ -43,6 +43,7 @@ import com.android.common.io.MoreCloseables; import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; +import java.io.IOException; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.RejectedExecutionException; @@ -124,6 +125,7 @@ public class VoicemailPlaybackPresenter private Uri mVoicemailUri; private int mPosition; + private boolean mIsPrepared; private boolean mIsPlaying; private boolean mShouldResumePlaybackAfterSeeking; @@ -172,6 +174,7 @@ public class VoicemailPlaybackPresenter mView.setPresenter(this); + mIsPrepared = false; checkForContent(); } @@ -184,6 +187,11 @@ public class VoicemailPlaybackPresenter } public void onDestroy() { + if (mIsPrepared) { + mMediaPlayer.release(); + mIsPrepared = false; + } + if (mScheduledExecutorService != null) { mScheduledExecutorService.shutdown(); mScheduledExecutorService = null; @@ -350,7 +358,7 @@ public class VoicemailPlaybackPresenter mMediaPlayer.setDataSource(mContext, mVoicemailUri); mMediaPlayer.setAudioStreamType(PLAYBACK_STREAM); mMediaPlayer.prepareAsync(); - } catch (Exception e) { + } catch (IOException e) { handleError(e); } } @@ -360,6 +368,8 @@ public class VoicemailPlaybackPresenter */ @Override public void onPrepared(MediaPlayer mp) { + mIsPrepared = true; + mView.enableUiElements(); if (mIsPlaying) { @@ -380,7 +390,11 @@ public class VoicemailPlaybackPresenter } private void handleError(Exception e) { - mMediaPlayer.release(); + if (mIsPrepared) { + mMediaPlayer.release(); + mIsPrepared = false; + } + mView.onPlaybackError(e); setPosition(0, false); } |