0

I am using MediaPlayer to play a music in 60 seconds. I want to increase the sound of the music when it is playing follows the rule:

1. First 10 seconds, the volume is 20% of maximum volume
2. From 20 seconds to 30 seconds, the volume is 40% of maximum volume 
3. From 30 seconds to 40 seconds, the volume is 80% of maximum volume 
3. From 40 seconds to 60 seconds, the volume is 100% of maximum volume 

How can I control the volume of the MediaPlayer by programming in Android M?. This is my code to play music. It is missing the task control volume. Thank all

public MediaPlayer mpCalling = null;
private CountDownTimer mCountDownTimer_Playing;
public void playSound(){
    Uri notification = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_RINGTONE);
    try {
        if (mpCalling != null &&  mpCalling.isPlaying()) {
        mpCalling.stop();
        mpCalling.release();
        mpCalling=null;
        }
        mpCalling = MediaPlayer.create(getApplicationContext(), notification);
        mpCalling.start();
        if(mCountDownTimer_Playing!=null){
        mCountDownTimer_Playing.cancel();
        mCountDownTimer_Playing=null;
        }
        mCountDownTimer_Playing = new CountDownTimer(60000,1000) {
        @Override
        public void onTick(long millisUntilFinished) {

        }
        @Override
        public void onFinish() {
            mpCalling.stop();
        }
        };
        mCountDownTimer_Playing.start();
    } catch (Exception e) {
        e.printStackTrace();
    }
} 
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
John
  • 2,838
  • 7
  • 36
  • 65
  • You can do with [this](http://stackoverflow.com/a/30433243/5521469), get max volume and divide it according to use. – DwlRathod Jan 31 '17 at 10:59
  • Try this one [Mediaplayer](https://stackoverflow.com/questions/5215459/android-mediaplayer-setvolume-function). Hope this will help you. – Eldor Abdukhamidov Dec 21 '17 at 05:37

0 Answers0