(L1) AudioService AudioHandler setDeviceVolume, setAllVolumes, persistVolume
2015-07-14 14:01
435 查看
前言
setDeviceVolume, setAllVolumes, persistVolume是volume中较通用的函数@Override public void handleMessage(Message msg) { switch (msg.what) { case MSG_SET_DEVICE_VOLUME: setDeviceVolume((VolumeStreamState) msg.obj, msg.arg1); break; case MSG_SET_ALL_VOLUMES: setAllVolumes((VolumeStreamState) msg.obj); break; case MSG_PERSIST_VOLUME: persistVolume((VolumeStreamState) msg.obj, msg.arg1); break;http://blog.csdn.net/wlia/article/details/46877123
setDeviceVolume
private void setDeviceVolume(VolumeStreamState streamState, int device) { synchronized (VolumeStreamState.class) { // Apply volume streamState.applyDeviceVolume_syncVSS(device); // Apply change to all streams using this one as alias int numStreamTypes = AudioSystem.getNumStreamTypes(); for (int streamType = numStreamTypes - 1; streamType >= 0; streamType--) {
</pre><pre name="code" class="java">
src stream不同(其他的VolumeStreamState),<span style="font-family: Arial, Helvetica, sans-serif;">dst stream相同 (</span>dst stream 是该VolumeStreamState的src stream),那么必须有<span style="font-family: Arial, Helvetica, sans-serif;">VolumeStreamState的</span>src stream就是dst stream, 这种stream 没有alias
</pre><pre name="code" class="java"> if (streamType != streamState.mStreamType && mStreamVolumeAlias[streamType] == streamState.mStreamType) {
// Make sure volume is also maxed out on A2DP device for aliased stream // that may have a different device selected
</pre><pre name="code" class="java">get device int streamDevice = getDeviceForStream(streamType);
</pre><pre name="code" class="java">对A2DP有判断 if ((device != streamDevice) && mAvrcpAbsVolSupported && ((device & AudioSystem.DEVICE_OUT_ALL_A2DP) != 0)) { mStreamStates[streamType].applyDeviceVolume_syncVSS(device); }
apply mStreamStates[streamType].applyDeviceVolume_syncVSS(streamDevice); } } }
持久保存 // Post a persist volume msg sendMsg(mAudioHandler, MSG_PERSIST_VOLUME, SENDMSG_QUEUE, device, 0, streamState, PERSIST_DELAY); }http://blog.csdn.net/wlia/article/details/46877123
相关函数
applyDeviceVolume_syncVSS
通过getIndex取得数据,那么之前setIndex,所以这里传入device即可。
A2DP index max
<pre name="code" class="java">AudioSystem.setStreamVolumeIndex下派参数
public void applyDeviceVolume_syncVSS(int device) { int index; if (isMuted_syncVSS()) { index = 0; } else if (((device & AudioSystem.DEVICE_OUT_ALL_A2DP) != 0 && mAvrcpAbsVolSupported) || ((device & mFullVolumeDevices) != 0)) { index = (mIndexMax + 5)/10; } else { index = (getIndex(device) + 5)/10; } AudioSystem.setStreamVolumeIndex(mStreamType, index, device); }http://blog.csdn.net/wlia/article/details/46877123
persistVolume
private void persistVolume(VolumeStreamState streamState, int device) { if (mUseFixedVolume) { return; }
</pre><pre name="code" class="java">电视只有music才允许persist
if (isPlatformTelevision() && (streamState.mStreamType != AudioSystem.STREAM_MUSIC)) { return; } System.putIntForUser(mContentResolver, streamState.getSettingNameForDevice(device), (streamState.getIndex(device) + 5)/ 10, UserHandle.USER_CURRENT); }http://blog.csdn.net/wlia/article/details/46877123
setAllVolumes
private void setAllVolumes(VolumeStreamState streamState) { // Apply volume streamState.applyAllVolumes(); // Apply change to all streams using this one as alias int numStreamTypes = AudioSystem.getNumStreamTypes(); for (int streamType = numStreamTypes - 1; streamType >= 0; streamType--) { if (streamType != streamState.mStreamType && mStreamVolumeAlias[streamType] == streamState.mStreamType) { mStreamStates[streamType].applyAllVolumes(); } } }
http://blog.csdn.net/wlia/article/details/46877123
相关函数
applyAllVolumes
public void applyAllVolumes() {
synchronized (VolumeStreamState.class) {
<ul style="margin: 0px; padding: 0px; border: 0px; outline: 0px; list-style: none; color: rgb(67, 67, 67); font-family: Tahoma, Arial; line-height: 24px; widows: auto; background-color: rgb(242, 242, 242);"><li style="margin: 0px; padding: 0px; border: 0px; outline: 0px; list-style: none;">按照惯例,<span style="widows: auto; background-color: rgb(240, 240, 240);">apply default volume first.看来是AudioPolicyManager需要</span></li></ul> // apply default volume first: by convention this will reset all // devices volumes in audio policy manager to the supplied value
int index;
有Mute则为0 if (isMuted_syncVSS()) { index = 0; } else { index = (getIndex(AudioSystem.DEVICE_OUT_DEFAULT) + 5)/10; }
下派参数 AudioSystem.setStreamVolumeIndex(mStreamType, index, AudioSystem.DEVICE_OUT_DEFAULT); // then apply device specific volumes
对mIndex中每个选项进行处理Set set = mIndex.entrySet();Iterator i = set.iterator();while (i.hasNext()) {Map.Entry entry = (Map.Entry)i.next();int device <span style="font-family: Arial, Helvetica, sans-serif;">= ((Integer)entry.getKey()).intValue();</span>
<span style="font-family: Arial, Helvetica, sans-serif;"></span>
如果是default device,则不再处理。。。这些代码真臭!if( == out default) return;更好!Google也不过如此。
if (device != AudioSystem.DEVICE_OUT_DEFAULT) {
还是先处理muteif (isMuted_syncVSS()) {index = 0;
out A2DP, mAvrcpAbsVolSupported则max} else if (((device & AudioSystem.DEVICE_OUT_ALL_A2DP) != 0 &&mAvrcpAbsVolSupported)|| ((device & mFullVolumeDevices) != 0)){index = (mIndexMax + 5)/10;} else {
最普通的情况往往在最后index = ((Integer)entry.getValue() + 5)/10;}AudioSystem.setStreamVolumeIndex(mStreamType, index, device);}}}}
http://blog.csdn.net/wlia/article/details/46877123
相关文章推荐
- IOS中判断设备型号的宏定义
- iOS正则表达式
- iOS正则表达式 分类: ios技术 2015-07-14 14:00 35人阅读 评论(0) 收藏
- iOS解决两个静态库的冲突 duplicate symbol
- IOS 开发 手势使用
- IOS 添加libMobileVLCKit .a到项目中编译问题
- phonegap(cordova) 入门 5----小知识点总结------------ios 选择默认语言
- iOS 的事件处理
- 个人常用iOS第三方库以及XCode插件介绍
- [转] iOS --- 自定义CoreData迁移
- 【iOS开发系列】KVC&KVO
- iOS——MVVM设计模式
- ios修改NavigationController的背景颜色
- 中文 iOS/Mac 开发博客列表
- 小胖说事27-----IOS制作自已的静态framework
- ios开发 向右滑动手势实现返回.在NavigationController中如何设置
- phonegap(cordova) 入门 9----小知识点总结--iOS 状态栏的字体颜色都设置为白色
- IOS中的ViewController 的loadView、viewDidLoad、viewDidUnload
- IOS-使用blend改变图片颜色
- IOS日期转为今天昨天形式