How can i get the minimum volume?

泪湿孤枕 提交于 2021-02-10 04:21:56

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!