(1)settings内,可设置音频流音量,如下图:
(2)settings调整音量条进度,会触发SeekBarVolumizer对象:
SeekBarVolumizer文件路径:
frameworks/base/core/java/android/preference/SeekBarVolumizer.java
SeekBarVolumizer对象,handle会接到MSG_SET_STREAM_VOLUME事件:
public boolean handleMessage(Message msg) {
switch (msg.what) {
case MSG_SET_STREAM_VOLUME:
if (mMuted && mLastProgress > 0) {
mAudioManager.adjustStreamVolume(mStreamType, AudioManager.ADJUST_UNMUTE, 0);
} else if (!mMuted && mLastProgress == 0) {
mAudioManager.adjustStreamVolume(mStreamType, AudioManager.ADJUST_MUTE, 0);
}
mAudioManager.setStreamVolume(mStreamType, mLastProgress,AudioManager.FLAG_SHOW_UI_WARNINGS);
break;
...
}
return true;
}
(3)调用AudioManager对象,执行对应流音量大小调整:
AudioManager文件路径:
frameworks/base/media/java/android/media/AudioManager.java
AudioManager对象执行,音量调整函数:
public void setStreamVolume(int streamType, int index, int flags) {
final IAudioService service = getService();
try {
service.setStreamVolume(streamType, index, flags, getContext().getOpPackageName());
} catch (RemoteException e) {
throw e.rethrowFromSystemServer();
}
}
在设置APK内,触发不同音量进度条,会拉起setStreamVolume()函数,完成对应音频流音量大小调整。