From 9d6e3b2700f8011645bc3e76b118d4c615b630d6 Mon Sep 17 00:00:00 2001 From: Nancy Chen Date: Wed, 16 Sep 2015 15:21:51 -0700 Subject: Display duration and prepare voicemail if voicemail is downloaded. We should always know what the duration of the voicemail is even before it is downloaded. As such, when a voicemail is expanded, set the voicemail duration. For a downloaded voicemail, we can go even further and prepare the audio file when the card is expanded. This means the voicemail can be played immediately when the user clicks "play" instead of having to wait for the media player to buffer each time. Bug: 23566924 Change-Id: I0ce7570eab72b0bf079d3eb8cd10b71981576a9f --- .../dialer/voicemail/VoicemailPlaybackLayout.java | 5 ----- .../dialer/voicemail/VoicemailPlaybackPresenter.java | 16 ++++++++++------ 2 files changed, 10 insertions(+), 11 deletions(-) (limited to 'src/com/android/dialer/voicemail') diff --git a/src/com/android/dialer/voicemail/VoicemailPlaybackLayout.java b/src/com/android/dialer/voicemail/VoicemailPlaybackLayout.java index 14c5473ae..698530b69 100644 --- a/src/com/android/dialer/voicemail/VoicemailPlaybackLayout.java +++ b/src/com/android/dialer/voicemail/VoicemailPlaybackLayout.java @@ -276,9 +276,7 @@ public class VoicemailPlaybackLayout extends LinearLayout mDeleteButton.setOnClickListener(mDeleteButtonListener); mPositionText.setText(formatAsMinutesAndSeconds(0)); - mPositionText.setVisibility(View.INVISIBLE); mTotalDurationText.setText(formatAsMinutesAndSeconds(0)); - mTotalDurationText.setVisibility(View.INVISIBLE); } @Override @@ -368,9 +366,6 @@ public class VoicemailPlaybackLayout extends LinearLayout mStartStopButton.setEnabled(false); mPlaybackSeek.setProgress(0); mPlaybackSeek.setEnabled(false); - - mPositionText.setText(formatAsMinutesAndSeconds(0)); - mTotalDurationText.setText(formatAsMinutesAndSeconds(0)); } @Override diff --git a/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java b/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java index 95622bfa2..208096dac 100644 --- a/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java +++ b/src/com/android/dialer/voicemail/VoicemailPlaybackPresenter.java @@ -101,6 +101,7 @@ public class VoicemailPlaybackPresenter implements MediaPlayer.OnPreparedListene private static final String[] HAS_CONTENT_PROJECTION = new String[] { VoicemailContract.Voicemails.HAS_CONTENT, + VoicemailContract.Voicemails.DURATION }; private static final int NUMBER_OF_THREADS_IN_POOL = 2; @@ -256,14 +257,13 @@ public class VoicemailPlaybackPresenter implements MediaPlayer.OnPreparedListene mView.onSpeakerphoneOn(mIsSpeakerphoneOn); } - mDuration.set(0); + checkForContent(); if (startPlayingImmediately) { // Since setPlaybackView can get called during the view binding process, we don't // want to reset mIsPlaying to false if the user is currently playing the // voicemail and the view is rebound. mIsPlaying = startPlayingImmediately; - checkForContent(); } } } @@ -360,7 +360,7 @@ public class VoicemailPlaybackPresenter implements MediaPlayer.OnPreparedListene if (hasContent) { prepareContent(); } else { - requestContent(); + mView.setClipPosition(0, mDuration.get()); } } }); @@ -373,10 +373,14 @@ public class VoicemailPlaybackPresenter implements MediaPlayer.OnPreparedListene ContentResolver contentResolver = mContext.getContentResolver(); Cursor cursor = contentResolver.query( - voicemailUri, HAS_CONTENT_PROJECTION, null, null, null); + voicemailUri, null, null, null, null); try { if (cursor != null && cursor.moveToNext()) { - return cursor.getInt(cursor.getColumnIndexOrThrow( + int duration = cursor.getInt(cursor.getColumnIndex( + VoicemailContract.Voicemails.DURATION)); + // Convert database duration (seconds) into mDuration (milliseconds) + mDuration.set(duration > 0 ? duration * 1000 : 0); + return cursor.getInt(cursor.getColumnIndex( VoicemailContract.Voicemails.HAS_CONTENT)) == 1; } } finally { @@ -604,7 +608,7 @@ public class VoicemailPlaybackPresenter implements MediaPlayer.OnPreparedListene if (!mIsPrepared) { // If we haven't downloaded the voicemail yet, attempt to download it. - checkForContent(); + requestContent(); mIsPlaying = true; return; } -- cgit v1.2.3