Media player not functioning correctly

Monday, June 30, 2014

Excuse my backwards programming methods, I am new still new to android. Before my program was stopping when the listener heard a new click, now it just continues playing, I am not sure what exactly is the issue. I feel it is probably my backwards programming. Any ideas?



public class MusicActivity extends ActionBarActivity {


MediaPlayer mp;
Button downloadJosmo;
Button downloadKillah;
Button downloadProblems;
Button downloadSolo;
Button downloadStressin;
Button playKillah;
Button playProblems;
Button playSolo;
Button playStressin;
Button playJosmo;
Button stopPreview;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.music_activity);

playKillah = (Button) findViewById(R.id.playkillah);
playProblems = (Button) findViewById(R.id.playproblems);
playSolo = (Button) findViewById(R.id.playsolo);
playStressin = (Button) findViewById(R.id.playstressin);
mp = MediaPlayer.create(this, R.raw.ambitionsofakillah);
stopPreview = (Button) findViewById(R.id.stoppreview);
stopPreview.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
mp.pause();

}
});
playKillah.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
if(mp.isPlaying()) {
mp.stop();
mp.reset();
mp = MediaPlayer.create(MusicActivity.this, R.raw.ambitionsofakillah);
}
mp.start();
mp.setOnCompletionListener(new OnCompletionListener() {

@Override
public void onCompletion(MediaPlayer mp) {
mp.stop();
}
});
}

});
playProblems.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
if(mp.isPlaying()) {
mp.stop();
mp.reset();
mp = MediaPlayer.create(MusicActivity.this, R.raw.saltygotproblems);
}
mp.start();
mp.setOnCompletionListener(new OnCompletionListener() {

@Override
public void onCompletion(MediaPlayer mp) {
mp.stop();
}
});
}

});
playSolo.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
if(mp.isPlaying()) {
mp.stop();
mp.reset();
mp = MediaPlayer.create(MusicActivity.this, R.raw.solodolo);
}
mp.start();
mp.setOnCompletionListener(new OnCompletionListener() {

@Override
public void onCompletion(MediaPlayer mp) {
mp.stop();
}
});
}

});
playStressin.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
if(mp.isPlaying()) {
mp.stop();
mp.reset();
mp = MediaPlayer.create(MusicActivity.this, R.raw.stressin);
}
mp.start();
mp.setOnCompletionListener(new OnCompletionListener() {

@Override
public void onCompletion(MediaPlayer mp) {
mp.stop();
}
});
}

});

downloadKillah = (Button) findViewById(R.id.downloadkillah);
downloadProblems = (Button) findViewById(R.id.downloadproblems);
downloadSolo = (Button) findViewById(R.id.downloadsolo);
downloadStressin = (Button) findViewById(R.id.downloadstressin);

downloadKillah.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
String killahUrl = "http://ift.tt/VBB848";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(killahUrl));
startActivity(i);

}
});
downloadProblems.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
String problemsUrl = "http://ift.tt/1luqTU2";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(problemsUrl));
startActivity(i);
}
});
downloadSolo.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
String soloUrl = "http://ift.tt/1luqReV";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(soloUrl));
startActivity(i);
}
});
downloadStressin.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
String stressinUrl = "http://ift.tt/1luqReX";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(stressinUrl));
startActivity(i);
}
});
playJosmo = (Button) findViewById(R.id.playjosmo);
playJosmo.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
if(mp.isPlaying()) {
mp.stop();
mp.reset();
mp = MediaPlayer.create(MusicActivity.this, R.raw.josmo);
}
mp.start();
mp.setOnCompletionListener(new OnCompletionListener() {

@Override
public void onCompletion(MediaPlayer mp) {
mp.stop();
}

});

}
});
downloadJosmo = (Button) findViewById(R.id.downloadjosmo);
downloadJosmo.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
String josmoUrl = "http://ift.tt/VBB84c";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(josmoUrl));
startActivity(i);

}
});
}
}






http://ift.tt/1luqTU4