问题
I know that code below is the max volume
mAudioManager.getStreamMaxVolume
how can i get the minimum volume?
I used this code but not the minimum volume
mAudioManager.getStreamVolume(0);
This my code
int Minvolume=myAudioManager.getStreamVolume(0);
int current=myAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
int volume=(int) (current-1);
if (current>=Minvolume){
myAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0);
handler.postDelayed(this, 10000);
System.out.println("ADJUST LOWER");
}
else if (current!=Minvolume){
System.out.println("volume is minimum");
}
回答1:
Try the following to reduce the volume of the music stream...
for (int volume = myAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC) - 1; volume >= 0; volume--) {
//
// add your delay code here
//
// Call a method to set absolute volume
setVolume(volume);
}
private void setVolume(int volume) {
myAudioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0);
}
回答2:
A better approach to increase or decrease volume would be to use adjustVolume.
public void decreaseStreamVolume(int volType, AudioManager am){
am.adjustStreamVolume(volType, AudioManager.ADJUST_LOWER, AudioManager.FLAG_SHOW_UI + AudioManager.FLAG_PLAY_SOUND);
}
You can enter AudioManager.STREAM_MUSIC or any desirable stream and AudioManager.ADJUST_LOWER or AudioManager.ADJUST_HIGHER as per your requirement. I believe it's much cleaner way to execute.
来源:https://stackoverflow.com/questions/29684357/how-can-i-get-the-minimum-volume