RingtoneManager

来源:互联网 发布:网络销售授权书模板 编辑:程序博客网 时间:2024/06/02 09:07

铃声学习
RingtoneManager.getRingtone(context, ringtoneUri);获取铃声Ringtone对象
不管哪里用到铃声,都会有弹出一个Dialog 选择铃声 因此我们自己使用的时候应该

通过intent+action 弹出,这个界面在/packages/providers/MediaProvide然后就是com.android.providor.media.RingtonePickerActivity.java
是以对话框的形式因此extend Alertctivity

action是有几种选择:
RingtoneManager.ACTION_RINGTONE_PICKER Activity Action: Shows a ringtone picker.展现铃声选择弹窗
RingtoneManager.EXTRA_RINGTONE_SHOW_DEFAULT 传递一个boolean值是否弹出默认选项 默认铃声 Settings.System.DEFAULT_RINGTONE_URI;
RingtonrManager.EXTRA_RINGTONE_SHOW_SILENT 是否有静音选项
RingtoneManager.EXTRA_RINGTONE_SHOW_MORE_RINGTONES 是否有更多铃声选项
RingtoneManager.EXTRA_RINGTONE_EXISTING_URI 打开对话框的时候就默认选中上次被选中的音乐
/**
* Given to the ringtone picker as a {@link Uri}. The {@link Uri} of the
* current ringtone, which will be used to show a checkmark next to the item
* for this {@link Uri}. If showing an item for “Default” (@see
* {@link #EXTRA_RINGTONE_SHOW_DEFAULT}), this can also be one of
* {@link System#DEFAULT_RINGTONE_URI},
* {@link System#DEFAULT_NOTIFICATION_URI},
* {@link System#DEFAULT_ALARM_ALERT_URI}, or
* M: { System#DEFAULT_VIDEO_CALL_URI} to have the “Default” item
* checked.
*
* @see #ACTION_RINGTONE_PICKER
*/
看懂大概意思:如有有Default选项,那么 * {@link System#DEFAULT_RINGTONE_URI},* {@link System#DEFAULT_NOTIFICATION_URI},* {@link System#DEFAULT_ALARM_ALERT_URI}, M: { System#DEFAULT_VIDEO_CALL_URI} 那么也要有这四个选项主要是URI
RingtoneManager.EXTRA_RINGTONE_TYPE 根据铃声类型指定是否显示,有type Notification,Alarm,all
RingtoneManager.EXTRA_RINGTONE_TITLE 展现铃声的title
RingtoneManager.EXTRA_RINGTONE_AUDIO_ATTRIBUTES_FLAGS 铃声额外的属性
RingtoneManager.EXTRA_RINGTONE_PICKED_URI 已被选的铃声的URI,DEFAULT_VIDEO_CALL_URI选的是系统默认,选silent,那么是null
RingtoneManager.EXTRA_RINGTONE_PICKED_POSITION 选的位置

RingtonePickerActivity中根据获得的值设置弹框
然后获取type值intent.getIntExtra(RingtoneManager.EXTRA_RINGTONE_TYPE, -1);
所有属性列出来看一下:
Type that refers to sounds that are used for the phone ringer.
TYPE_RINGTONE = 1;
Type that refers to sounds that are used for notifications.
TYPE_NOTIFICATION = 2;
Type that refers to sounds that are used for the alarm.
TYPE_ALARM = 4;
Type that refers to sounds that are used for the video call phone ringer.
TYPE_VIDEO_CALL = 8;
Type that refers to sounds that are used for the sip call phone ringer.
TYPE_SIP_CALL = 16;
All types of sounds.
TYPE_ALL = TYPE_RINGTONE | TYPE_NOTIFICATION | TYPE_ALARM;

然后 setVolumeControlStream(mRingtoneManager.inferStreamType());这个是表示音量键控制哪种音频的开关
public int inferStreamType() {
switch (mType) {

        case TYPE_ALARM:            return AudioManager.STREAM_ALARM;        case TYPE_NOTIFICATION:            return AudioManager.STREAM_NOTIFICATION;        default:            return AudioManager.STREAM_RING;    }}

一共有三种进入AudioManager
/* The audio stream for phone calls /
public static final int STREAM_VOICE_CALL = AudioSystem.STREAM_VOICE_CALL;
/* The audio stream for system sounds /
public static final int STREAM_SYSTEM = AudioSystem.STREAM_SYSTEM;
/* The audio stream for the phone ring /
public static final int STREAM_RING = AudioSystem.STREAM_RING;
/* The audio stream for music playback /
public static final int STREAM_MUSIC = AudioSystem.STREAM_MUSIC;
/* The audio stream for alarms /
public static final int STREAM_ALARM = AudioSystem.STREAM_ALARM;
/* The audio stream for notifications /
public static final int STREAM_NOTIFICATION = AudioSystem.STREAM_NOTIFICATION;
/* @hide The audio stream for phone calls when connected to bluetooth /
public static final int STREAM_BLUETOOTH_SCO = AudioSystem.STREAM_BLUETOOTH_SCO;
/* @hide The audio stream for enforced system sounds in certain countries (e.g camera in Japan) /
public static final int STREAM_SYSTEM_ENFORCED = AudioSystem.STREAM_SYSTEM_ENFORCED;
/* The audio stream for DTMF Tones /
public static final int STREAM_DTMF = AudioSystem.STREAM_DTMF;
/* @hide The audio stream for text to speech (TTS) /
public static final int STREAM_TTS = AudioSystem.STREAM_TTS;
可以看出使用的是AudioSystem.java进入看一下
/* The default audio stream */
public static final int STREAM_DEFAULT = -1;
/* The audio stream for phone calls */
public static final int STREAM_VOICE_CALL = 0;
/* The audio stream for system sounds */
public static final int STREAM_SYSTEM = 1;
/* The audio stream for the phone ring and message alerts */
public static final int STREAM_RING = 2;
/* The audio stream for music playback */
public static final int STREAM_MUSIC = 3;
/* The audio stream for alarms */
public static final int STREAM_ALARM = 4;
/* The audio stream for notifications */
public static final int STREAM_NOTIFICATION = 5;
/* @hide The audio stream for phone calls when connected on bluetooth */
public static final int STREAM_BLUETOOTH_SCO = 6;
/* @hide The audio stream for enforced system sounds in certain countries (e.g camera in Japan) */
public static final int STREAM_SYSTEM_ENFORCED = 7;
/* @hide The audio stream for DTMF tones */
public static final int STREAM_DTMF = 8;
/* @hide The audio stream for text to speech (TTS) */
public static final int STREAM_TTS = 9;
/**

可以看到参数使用

RingtoneManager.getRingtone(context, ringtoneUri);获取铃声Ringtone对象这个方法还没研究透彻
AudioManager mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
IRingtonePlayer player = mAudioManager.getRingtonePlayer();

0 0
原创粉丝点击