Android设备使用wifi-direct,将屏幕投射到其他设备时,本地调节音量会从最大直接到最小,或者最小直接到最大。
究其原因:
428 // Devices for which thevolume is fixed and VolumePanel slider should be disabled
>> 429 final int mFixedVolumeDevices =AudioSystem.DEVICE_OUT_AUX_DIGITAL |
430 AudioSystem.DEVICE_OUT_DGTL_DOCK_HEADSET |
431 AudioSystem.DEVICE_OUT_ALL_USB |
432 AudioSystem.DEVICE_OUT_PROXY; // use fixed volume on proxy device(WiFidisplay)
在连接WFD的时候,音频调节是直接从最大到最小的。
在AudioService.java中
794 public voidadjustSuggestedStreamVolume(int direction, int suggestedStreamType, int flags,
862 flags &=~AudioManager.FLAG_FIXED_VOLUME;
863 if ((streamTypeAlias== AudioSystem.STREAM_MUSIC) &&
>> 864 ((device & mFixedVolumeDevices) != 0)) {
>> 865 flags |=AudioManager.FLAG_FIXED_VOLUME;
866
867 // Always togglebetween max safe volume and 0 for fixed volume devices where safe
868 // volume isenforced, and max and 0 for the others.
869 // This issimulated by stepping by the full allowed volume range
870 if(mSafeMediaVolumeState == SAFE_MEDIA_VOLUME_ACTIVE &&
871 (device& mSafeMediaVolumeDevices) != 0) {
872 step =mSafeMediaVolumeIndex;
873 } else {
874 step =streamState.getMaxIndex();
875 }
876 if (aliasIndex !=0) {
877 aliasIndex =step;
878 }
当为FLAG_FIXED_VOLUME时,单步调节值直接为最大。