I am new to android. I'm trying to create a music player which will play specific MP3 with one button(play/pause).I want button's background change between two image when click
Asked
Active
Viewed 63 times
-5
-
1Welcome to Stack Overflow. Please read [Stack Overflow: How to ask](http://stackoverflow.com/questions/how-to-ask) and [Jon Skeet's Question Checklist](http://msmvps.com/blogs/jon_skeet/archive/2012/11/24/stack-overflow-question-checklist.aspx) to find out how to ask a good question that will generate good useful, answers. – Our Man in Bananas Jul 15 '14 at 14:28
1 Answers
1
try this....
mp is mediaplayer object
use your image at btn_play and btn_pause
btnPlay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// check for already playing
if(mp.isPlaying()){
if(mp!=null){
mp.pause();
// Changing button image to play button
btnPlay.setImageResource(R.drawable.btn_play);
}
}else{
// Resume song
if(mp!=null){
mp.start();
// Changing button image to pause button
btnPlay.setImageResource(R.drawable.btn_pause);
}
}
}
});
-
Concise and to the point. However, it might be beneficial to show OP quickly how to set which MP3 file is assigned to the MediaPlayer. – krodmannix Jul 15 '14 at 14:06