Android 如何通过编程控制MediaPlayer的音量?
我正在使用Android 如何通过编程控制MediaPlayer的音量?,android,audio,android-mediaplayer,Android,Audio,Android Mediaplayer,我正在使用MediaPlayer在60秒内播放音乐。我希望在播放音乐时按照以下规则增加声音: 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. F
MediaPlayer
在60秒内播放音乐。我希望在播放音乐时按照以下规则增加声音:
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
如何通过Android M编程控制MediaPlayer的音量?。这是我播放音乐的代码。它缺少任务控制卷。谢谢大家
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();
}
}
您可以使用,获取最大音量并根据使用情况进行划分。试试这个。希望这对你有帮助。