Skip to content Skip to sidebar Skip to footer

How To Play A Specifc Audio File From Android In Build Rintone List?

I need to know is it possible to play a particular audio file from android in-built ringtone files. For example assume Tone_23 is in android ringtone list, now i need to play this

Solution 1:

You can try some thing like this :

/**
 * Play ring tone.
 *
 * @param ringToneTitle the ring tone title
 */voidplayRingTone(String ringToneTitle) {
    RingtoneManager ringtoneManager = newRingtoneManager(
            getApplicationContext());
    ringtoneManager.setType(RingtoneManager.TYPE_RINGTONE);

    int length = ringtoneManager.getCursor().getCount();

    for (int i = 0; i < length; i++) {
        Ringtone mRingtone = ringtoneManager.getRingtone(i);
        if (mRingtone != null) {
            Log.d("ringtoneTitle ", mRingtone.getTitle(getApplicationContext()));
            if(ringToneTitle.equalsIgnoreCase(mRingtone
                        .getTitle(getApplicationContext())) {
                mRingtone.play();
            }
        }
    }
}

Hope this helps.

Added : Also have a look at this class RingtoneManager

RingtoneManager provides access to ringtones, notification, and other types of sounds. It manages querying the different media providers and combines the results into a single cursor. It also provides a Ringtone for each ringtone. We generically call these sounds ringtones, however the TYPE_RINGTONE refers to the type of sounds that are suitable for the phone ringer.

Solution 2:

I think you can only play the ringtone that is set in the system automatically with for example:

Urinotification= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtoner= RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();

If you would always want to play a specific tone/file you would have to add it to your assets and play it from there.

Post a Comment for "How To Play A Specifc Audio File From Android In Build Rintone List?"