I am new to android and I am trying to develop an application in which I take two music files. When the application starts the first music, when the user presses the button, the second music is played, and the first music slowly disappears.
I tried this, but in the end I played two music files one by one. I cannot figure out how to deduce the effect of fading out.
Here is my sample code
package com.Audio;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Button;
public class DemoAudio extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
MediaPlayer mp=MediaPlayer.create(getBaseContext(), R.raw.fruit_dance);
mp.start();
mp.setVolume(1.0f, 1.0f);
Button btn=(Button) findViewById(R.id.xBtn);
btn.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event){
if(event.getAction()==MotionEvent.ACTION_DOWN){
final MediaPlayer mp1=MediaPlayer.create(getBaseContext(), R.raw.futurebells_full);
mp1.start();
mp1.setVolume(5.0f, 5.0f);
}
return true;
}
});
}
}
Any help would be appreciated. Many thanks.
source
share