Methods Summary |
---|
public int | getStreamType()Gets the stream type where this ringtone will be played.
return mStreamType;
|
public java.lang.String | getTitle(android.content.Context context)Returns a human-presentable title for ringtone. Looks in media and DRM
content providers. If not in either, uses the filename
if (mTitle != null) return mTitle;
return mTitle = getTitle(context, mUri, true);
|
private static java.lang.String | getTitle(android.content.Context context, android.net.Uri uri, boolean followSettingsUri)
Cursor cursor = null;
ContentResolver res = context.getContentResolver();
String title = null;
if (uri != null) {
String authority = uri.getAuthority();
if (Settings.AUTHORITY.equals(authority)) {
if (followSettingsUri) {
Uri actualUri = RingtoneManager.getActualDefaultRingtoneUri(context,
RingtoneManager.getDefaultType(uri));
String actualTitle = getTitle(context, actualUri, false);
title = context
.getString(com.android.internal.R.string.ringtone_default_with_actual,
actualTitle);
}
} else {
if (DrmStore.AUTHORITY.equals(authority)) {
cursor = res.query(uri, DRM_COLUMNS, null, null, null);
} else if (MediaStore.AUTHORITY.equals(authority)) {
cursor = res.query(uri, MEDIA_COLUMNS, null, null, null);
}
if (cursor != null && cursor.getCount() == 1) {
cursor.moveToFirst();
return cursor.getString(2);
} else {
title = uri.getLastPathSegment();
}
}
}
if (title == null) {
title = context.getString(com.android.internal.R.string.ringtone_unknown);
if (title == null) {
title = "";
}
}
return title;
|
public boolean | isPlaying()Whether this ringtone is currently playing.
return mAudio != null && mAudio.isPlaying();
|
void | open(java.io.FileDescriptor fd)
mFileDescriptor = fd;
openMediaPlayer();
|
void | open(android.content.res.AssetFileDescriptor fd)
mAssetFileDescriptor = fd;
openMediaPlayer();
|
void | open(android.net.Uri uri)
mUri = uri;
openMediaPlayer();
|
private void | openMediaPlayer()
mAudio = new MediaPlayer();
if (mUri != null) {
mAudio.setDataSource(mContext, mUri);
} else if (mFileDescriptor != null) {
mAudio.setDataSource(mFileDescriptor);
} else if (mAssetFileDescriptor != null) {
// Note: using getDeclaredLength so that our behavior is the same
// as previous versions when the content provider is returning
// a full file.
if (mAssetFileDescriptor.getDeclaredLength() < 0) {
mAudio.setDataSource(mAssetFileDescriptor.getFileDescriptor());
} else {
mAudio.setDataSource(mAssetFileDescriptor.getFileDescriptor(),
mAssetFileDescriptor.getStartOffset(),
mAssetFileDescriptor.getDeclaredLength());
}
} else {
throw new IOException("No data source set.");
}
mAudio.setAudioStreamType(mStreamType);
mAudio.prepare();
|
public void | play()Plays the ringtone.
if (mAudio == null) {
try {
openMediaPlayer();
} catch (Exception ex) {
Log.e(TAG, "play() caught ", ex);
mAudio = null;
}
}
if (mAudio != null) {
mAudio.start();
}
|
public void | setStreamType(int streamType)Sets the stream type where this ringtone will be played.
mStreamType = streamType;
if (mAudio != null) {
/*
* The stream type has to be set before the media player is
* prepared. Re-initialize it.
*/
try {
openMediaPlayer();
} catch (IOException e) {
Log.w(TAG, "Couldn't set the stream type", e);
}
}
|
void | setTitle(java.lang.String title)
mTitle = title;
|
public void | stop()Stops a playing ringtone.
if (mAudio != null) {
mAudio.reset();
mAudio.release();
mAudio = null;
}
|