1

我需要知道是否可以从 android 内置铃声文件中播放特定的音频文件。例如假设 Tone_23 在 android 铃声列表中,现在我需要在单击按钮时播放这个特定的铃声。我在 Google 中搜索得到了如何调用/显示 RingtonePicker 活动的指导(将显示整个铃声列表)。如果这可能意味着,请分享您的想法。提前致谢。

4

2 回答 2

2

你可以尝试这样的事情:

/**
 * Play ring tone.
 *
 * @param ringToneTitle the ring tone title
 */
void playRingTone(String ringToneTitle) {
    RingtoneManager ringtoneManager = new RingtoneManager(
            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();
            }
        }
    }
}

希望这可以帮助。

补充:也看看这个类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.

于 2012-09-25T18:21:11.177 回答
0

我认为您只能播放系统中自动设置的铃声,例如:

Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
Ringtone r = RingtoneManager.getRingtone(getApplicationContext(), notification);
r.play();

如果您总是想播放特定的音调/文件,则必须将其添加到您的资产中并从那里播放。

于 2012-09-25T18:07:33.890 回答