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();
}
}