링크 된 example을 보면 일정 기간 동안 볼륨을 높이거나 낮추려면 루프에서 fadeIn()/fadeOut()을 호출해야합니다. deltaTime은 루프의 각 반복 사이의 시간이됩니다.
메인 UI 스레드와 별도의 스레드에서이 작업을 수행해야하므로이를 차단하지 않아 앱이 중단 될 수 있습니다. 새로운 Thread/Runnable/Timer에이 루프를 넣음으로써이를 수행 할 수 있습니다. 나는 귀하의 경우 사용 하나에서와 트랙을 교체,
int volume = 0;
private void startFadeIn(){
final int FADE_DURATION = 3000; //The duration of the fade
//The amount of time between volume changes. The smaller this is, the smoother the fade
final int FADE_INTERVAL = 250;
final int MAX_VOLUME = 1; //The volume will increase from 0 to 1
int numberOfSteps = FADE_DURATION/FADE_INTERVAL; //Calculate the number of fade steps
//Calculate by how much the volume changes each step
final float deltaVolume = MAX_VOLUME/(float)numberOfSteps;
//Create a new Timer and Timer task to run the fading outside the main UI thread
final Timer timer = new Timer(true);
TimerTask timerTask = new TimerTask() {
@Override
public void run() {
fadeInStep(deltaVolume); //Do a fade step
//Cancel and Purge the Timer if the desired volume has been reached
if(volume>=1f){
timer.cancel();
timer.purge();
}
}
};
timer.schedule(timerTask,FADE_INTERVAL,FADE_INTERVAL);
}
private void fadeInStep(float deltaVolume){
mediaPlayer.setVolume(volume, volume);
volume += deltaVolume;
}
대신 두 개의 MediaPlayer를 개체를 사용하여 : 여기
내 (당신이 페이드 아웃에 대한 비슷한 일을 할 수있는) 페이딩에 대한 예입니다 페이드 사이. 예 :
**Audio track #1 is playing but coming to the end**
startFadeOut();
mediaPlayer.stop();
mediaPlayer.reset();
mediaPlayer.setDataSource(context,audiofileUri);
mediaPlayer.prepare();
mediaPlayer.start();
startFadeIn();
**Audio track #2 has faded in and is now playing**
희망이 당신의 문제를 해결합니다.
아직 다른 해결책을 찾지 못해서 도움이됩니다. 또한 새로운 스레드에서 이것을 실행하는 힌트도 매우 유용합니다! 감사! – olop01