How do I get the current volume/amplitude in a MediaPlayer?

前端 未结 7 897
孤街浪徒
孤街浪徒 2020-12-13 20:26

I\'m working on an app that will both record an audio file, and then have the option to play back that file once it\'s been recorded. The UI has an EQ component that animat

7条回答
  •  失恋的感觉
    2020-12-13 20:35

    As follow:

    audioManager = (AudioManager) activity.getSystemService(Context.AUDIO_SERVICE);
    int volumeLevel = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
    int maxVolumeLevel = audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
    int volumePercent = (int) (((float) volumeLevel / maxVolumeLevel) * 100);
    

提交回复
热议问题