java - Android - MediaPlayer display volume levels graphically

I'm using MediaPlayer to play a song I have in my raw folder

mPlayer = MediaPlayer.create(this, R.raw.song1;);
mPlayer.start();

Is there a way I can visually see the volume levels as the song is playing? So something like this, but it can be very basic so I can tell when the song is loud or not

enter image description here

1 Answer

  1. Nicholas- Reply

    2019-11-13

    It is actualy depend upon how much steps You want

    Let's suppose you want maximum volume of 100 steps

    int maxVolume = 100;

    then you can set to setVolume any value (0-99) in range try this:

     `float volume = (float)(Math.volume(maxVolume - currVolume)/Math.volume(maxVolume));`
    

    yourMediaPlayer.setVolume(1-volume);

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>