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

前端 未结 7 910
孤街浪徒
孤街浪徒 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条回答
  •  猫巷女王i
    2020-12-13 20:45

    You can get the current volume of media player with the help of Audiomanager class.The code is as follows:-

    AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE);
    int volume_level= am.getStreamVolume(AudioManager.STREAM_MUSIC);
    

    Similarly,if you want to set the default volume of media player.You can do that like as:-

    am.setStreamVolume(
                AudioManager.STREAM_MUSIC,
                volume_level,
                0);
    

    That's all..Happy coding :)

提交回复
热议问题