summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Marco Nelissen <marcone@google.com> 2012-11-16 13:03:33 -0800
committer Android Git Automerger <android-git-automerger@android.com> 2012-11-16 13:03:33 -0800
commit803db1646aedb451b76d33a4f30b16942c5d3ca4 (patch)
tree4df6095f298d52d5c083ae04aa7d204dcf9b7998
parent8f97174a9c9ea637301ffc19bb64369b74e1ab54 (diff)
parentaeb6268645d571dfc9f2d387a7ad2471039ddb54 (diff)
am aeb62686: Merge "Fallback to fallbackring if ringtone can\'t be played."
* commit 'aeb6268645d571dfc9f2d387a7ad2471039ddb54': Fallback to fallbackring if ringtone can't be played.
-rw-r--r--media/java/android/media/Ringtone.java47
1 files changed, 45 insertions, 2 deletions
diff --git a/media/java/android/media/Ringtone.java b/media/java/android/media/Ringtone.java
index f190eb978423..ebbfad96d94d 100644
--- a/media/java/android/media/Ringtone.java
+++ b/media/java/android/media/Ringtone.java
@@ -18,6 +18,8 @@ package android.media;
import android.content.ContentResolver;
import android.content.Context;
+import android.content.res.AssetFileDescriptor;
+import android.content.res.Resources.NotFoundException;
import android.database.Cursor;
import android.net.Uri;
import android.os.Binder;
@@ -229,10 +231,14 @@ public class Ringtone {
try {
mRemotePlayer.play(mRemoteToken, canonicalUri, mStreamType);
} catch (RemoteException e) {
- Log.w(TAG, "Problem playing ringtone: " + e);
+ if (!playFallbackRingtone()) {
+ Log.w(TAG, "Problem playing ringtone: " + e);
+ }
}
} else {
- Log.w(TAG, "Neither local nor remote playback available");
+ if (!playFallbackRingtone()) {
+ Log.w(TAG, "Neither local nor remote playback available");
+ }
}
}
@@ -280,6 +286,43 @@ public class Ringtone {
}
}
+ private boolean playFallbackRingtone() {
+ if (mAudioManager.getStreamVolume(mStreamType) != 0) {
+ int ringtoneType = RingtoneManager.getDefaultType(mUri);
+ if (ringtoneType != -1 &&
+ RingtoneManager.getActualDefaultRingtoneUri(mContext, ringtoneType) != null) {
+ // Default ringtone, try fallback ringtone.
+ try {
+ AssetFileDescriptor afd = mContext.getResources().openRawResourceFd(
+ com.android.internal.R.raw.fallbackring);
+ if (afd != null) {
+ mLocalPlayer = new MediaPlayer();
+ if (afd.getDeclaredLength() < 0) {
+ mLocalPlayer.setDataSource(afd.getFileDescriptor());
+ } else {
+ mLocalPlayer.setDataSource(afd.getFileDescriptor(),
+ afd.getStartOffset(),
+ afd.getDeclaredLength());
+ }
+ mLocalPlayer.setAudioStreamType(mStreamType);
+ mLocalPlayer.prepare();
+ mLocalPlayer.start();
+ afd.close();
+ return true;
+ } else {
+ Log.e(TAG, "Could not load fallback ringtone");
+ }
+ } catch (IOException ioe) {
+ destroyLocalPlayer();
+ Log.e(TAG, "Failed to open fallback ringtone");
+ } catch (NotFoundException nfe) {
+ Log.e(TAG, "Fallback ringtone does not exist");
+ }
+ }
+ }
+ return false;
+ }
+
void setTitle(String title) {
mTitle = title;
}