目录
- 前言
- 正文
- isDynamicRoutingEnabled()
- isAudioFeatureEnabled()
- setGroupVolume()
- getGroupMaxVolume()
- getGroupMinVolume()
- getGroupVolume()
- setFadeTowardFront()
- setBalanceTowardRight()
- getExternalSources()
- createAudioPatch()
- releaseAudioPatch()
- getVolumeGroupCount()
- getVolumeGroupIdForUsage()
- getAudioZoneIds()
- registerCarVolumeCallback()
- unregisterCarVolumeCallback()
- getUsagesForVolumeGroupId()
- 参考文章
前言
参考别人文章,看Android中车载部分CarAudioManager类中部分方法的介绍。
正文
简单记录一下CarAudioManager中方法的说明。
packages\services\Car\car-lib\src\android\car\media\CarAudioManager.java
isDynamicRoutingEnabled()
返回是否动态路由是否可用的。
public boolean isDynamicRoutingEnabled() { return isAudioFeatureEnabled(AUDIO_FEATURE_DYNAMIC_ROUTING); }
isDynamicRoutingEnabled高版本废弃了,替代的是
isAudioFeatureEnabled(AUDIO_FEATURE_DYNAMIC_ROUTING);
isAudioFeatureEnabled()
public boolean isAudioFeatureEnabled(@CarAudioFeature int audioFeature) { try { return mService.isAudioFeatureEnabled(audioFeature); } catch (RemoteException e) { return handleRemoteExceptionFromCarService(e, false); } }
setGroupVolume()
此方法有两个,一个是指定zoneId为PRIMARY_AUDIO_ZONE,一个是让用户指定zoneId,然后设置组音量的音量
public void setGroupVolume(int groupId, int index, int flags) { setGroupVolume(PRIMARY_AUDIO_ZONE, groupId, index, flags); } public void setGroupVolume(int zoneId, int groupId, int index, int flags) { try { mService.setGroupVolume(zoneId, groupId, index, flags); } catch (RemoteException e) { handleRemoteExceptionFromCarService(e); } }
getGroupMaxVolume()
获取组最大音量值(跟上面类似,两个方法)
public int getGroupMaxVolume(int groupId) { return getGroupMaxVolume(PRIMARY_AUDIO_ZONE, groupId); } public int getGroupMaxVolume(int zoneId, int groupId) { try { return mService.getGroupMaxVolume(zoneId, groupId); } catch (RemoteException e) { return handleRemoteExceptionFromCarService(e, 0); } }
getGroupMinVolume()
获取组最小音量值(跟上面类似,两个方法)
public int getGroupMinVolume(int groupId) { return getGroupMinVolume(PRIMARY_AUDIO_ZONE, groupId); } public int getGroupMinVolume(int zoneId, int groupId) { try { return mService.getGroupMinVolume(zoneId, groupId); } catch (RemoteException e) { return handleRemoteExceptionFromCarService(e, 0); } }
getGroupVolume()
获取groupId音量值(跟上面类似,两个方法)
public int getGroupVolume(int groupId) { return getGroupVolume(PRIMARY_AUDIO_ZONE, groupId); } public int getGroupVolume(int zoneId, int groupId) { try { return mService.getGroupVolume(zoneId, groupId); } catch (RemoteException e) { return handleRemoteExceptionFromCarService(e, 0); } }
setFadeTowardFront()
设置前后音量偏移,0.0是平衡,1.0是前面。
public void setFadeTowardFront(float value) { try { mService.setFadeTowardFront(value); } catch (RemoteException e) { handleRemoteExceptionFromCarService(e); } }
setBalanceTowardRight()
设置左右音量偏移,0.0是平衡,1.0是右面。
public void setBalanceTowardRight(float value) { try { mService.setBalanceTowardRight(value); } catch (RemoteException e) { handleRemoteExceptionFromCarService(e); } }
getExternalSources()
获取外部音源,除麦克风外的输入设备(警报音、DVD、收音机等)
public @NonNull String[] getExternalSources() { try { return mService.getExternalSources(); } catch (RemoteException e) { handleRemoteExceptionFromCarService(e); return new String[0]; } }
createAudioPatch()
通过getExternalSources给出的input port,创建一个外部音源到output的补丁,返回一个CarAudioPatchHandle。
public CarAudioPatchHandle createAudioPatch(String sourceAddress, @AttributeUsage int usage, int gainInMillibels) { try { return mService.createAudioPatch(sourceAddress, usage, gainInMillibels); } catch (RemoteException e) { return handleRemoteExceptionFromCarService(e, null); } }
这个不是很懂。。。
releaseAudioPatch()
跟createAudioPatch()配套使用。释放input port和output的关联。
public void releaseAudioPatch(CarAudioPatchHandle patch) { try { mService.releaseAudioPatch(patch); } catch (RemoteException e) { handleRemoteExceptionFromCarService(e); } }
getVolumeGroupCount()
有两个方法,一个是指定PRIMARY_AUDIO_ZONE的域,另外一个是用户传入域(zoneId)进行或可用音量组数目。
public int getVolumeGroupCount() { return getVolumeGroupCount(PRIMARY_AUDIO_ZONE); } public int getVolumeGroupCount(int zoneId) { try { return mService.getVolumeGroupCount(zoneId); } catch (RemoteException e) { return handleRemoteExceptionFromCarService(e, 0); } }
getVolumeGroupIdForUsage()
获取zoneId为PRIMARY_AUDIO_ZONE时,传入usage(音频用例)获取对应的音量组Id
public int getVolumeGroupIdForUsage(@AttributeUsage int usage) { return getVolumeGroupIdForUsage(PRIMARY_AUDIO_ZONE, usage); }
根据zoneId和usage(音频用例)获取对应的音量组Id
public int getVolumeGroupIdForUsage(int zoneId, @AttributeUsage int usage) { try { return mService.getVolumeGroupIdForUsage(zoneId, usage); } catch (RemoteException e) { return handleRemoteExceptionFromCarService(e, 0); } }
getAudioZoneIds()
获取所有音频域的id。
public @NonNull List<Integer> getAudioZoneIds() { try { int[] zoneIdArray = mService.getAudioZoneIds(); List<Integer> zoneIdList = new ArrayList<Integer>(zoneIdArray.length); for (int zoneIdValue : zoneIdArray) { zoneIdList.add(zoneIdValue); } return zoneIdList; } catch (RemoteException e) { return handleRemoteExceptionFromCarService(e, Collections.emptyList()); } }
registerCarVolumeCallback()
注册音量callback,添加到CarAudioManager维护的Callback组里,有onGroupVolumeChanged和onMasterMuteChanged的回调
public void registerCarVolumeCallback(@NonNull CarVolumeCallback callback) { Objects.requireNonNull(callback); if (mCarVolumeCallbacks.isEmpty()) { registerVolumeCallback(); } mCarVolumeCallbacks.add(callback); }
unregisterCarVolumeCallback()
取消注册
public void unregisterCarVolumeCallback(@NonNull CarVolumeCallback callback) { Objects.requireNonNull(callback); if (mCarVolumeCallbacks.remove(callback) && mCarVolumeCallbacks.isEmpty()) { unregisterVolumeCallback(); } }
getUsagesForVolumeGroupId()
两个方法,一个是指定zoneId为PRIMARY_AUDIO_ZONE,也就是通用域;另外一个是不指定,通过用户传入。
public @NonNull int[] getUsagesForVolumeGroupId(int groupId) { return getUsagesForVolumeGroupId(PRIMARY_AUDIO_ZONE, groupId); } public @NonNull int[] getUsagesForVolumeGroupId(int zoneId, int groupId) { try { return mService.getUsagesForVolumeGroupId(zoneId, groupId); } catch (RemoteException e) { return handleRemoteExceptionFromCarService(e, new int[0]); } }
参考文章
《