ok, i solved the nullpointexception and after this i got a illegalstateexception, now i made player to work. i knew which is the problem, and i know that the code is based on logic, but at that time my logic wasn't efficient, i got to sleep, and in the morning i allready had the answer in my head :)
created private void stopPlayers() // (coders will say i'm crazy:)
if (mp1.isPlaying()) { mp1.stop(); mp1.reset();}else if (mp2.isPlaying()){ mp2.stop(); mp2.reset();}else if (mp3.isPlaying()){ mp3.stop(); mp3.reset();}else if (mp4.isPlaying()){ mp4.stop(); mp4.reset();}else{ mp1.reset();
in each OnClickListener add stopPlayers()
Bot4.setOnClickListener(new OnClickListener(){
public void onClick(View v) { if(mp4.isPlaying()) { mp4.stop();} else { stopPlayers(); mp4 = MediaPlayer.create(getApplicationContext(), R.raw.tolflushs); mp4.start(); } } }); }
That's all, now if i have 10 buttons with 10 different songs i can play which song i want and the previous song will stop playing. and even if i'll hit the same button it will stop playing.