我想制作一个停止按钮以同时停止所有媒体播放器 和 如果可能,请在播放下一个声音之前让媒体播放器停止播放声音。所以声音不会相互影响。
重要的是制作一个停止按钮以同时停止所有媒体播放器。
MainActivity.java
package com.harshalpanpaliya.saluchan;
import android.media.MediaPlayer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final MediaPlayer aapSoundMediaPlayer = MediaPlayer.create(this, R.raw.upaar_wale_jab_upaar_bulana_tab);
final Button playCatMeow = (Button) this.findViewById(R.id.upaar_wale_jab_upaar_bulana_tab);
playCatMeow.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
aapSoundMediaPlayer.start();
}
});
final MediaPlayer bhopalSoundMediaPlayer = MediaPlayer.create(this, R.raw.bhopal);
final Button bhopal = (Button) this.findViewById(R.id.bhopal);
bhopal.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bhopalSoundMediaPlayer.start();
}
});
final MediaPlayer kamleshSoundMediaPlayer = MediaPlayer.create(this, R.raw.kamlesh);
final Button kamlesh = (Button) this.findViewById(R.id.kamlesh);
kamlesh.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
kamleshSoundMediaPlayer.start();
}
});
final MediaPlayer bhag_keSoundMediaPlayer = MediaPlayer.create(this, R.raw.bhag_ke);
final Button bhag_ke = (Button) this.findViewById(R.id.bhag_ke);
bhag_ke.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bhag_keSoundMediaPlayer.start();
}
});
final MediaPlayer bhagke_remixSoundMediaPlayer = MediaPlayer.create(this, R.raw.bhagke_remix);
final Button bhagke_remix = (Button) this.findViewById(R.id.bhagke_remix);
bhagke_remix.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bhagke_remixSoundMediaPlayer.start();
}
});
final MediaPlayer dun_dun_dunSoundMediaPlayer = MediaPlayer.create(this, R.raw.dun_dun_dun);
final Button dun_dun_dun = (Button) this.findViewById(R.id.dun_dun_dun);
dun_dun_dun.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dun_dun_dunSoundMediaPlayer.start();
}
});
final MediaPlayer how_to_use_saluchanSoundMediaPlayer = MediaPlayer.create(this, R.raw.how_to_use_saluchan);
final Button how_to_use_saluchan = (Button) this.findViewById(R.id.how_to_use_saluchan);
how_to_use_saluchan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
how_to_use_saluchanSoundMediaPlayer.start();
}
});
final MediaPlayer do_teen_din_nahi_piya_tha_naSoundMediaPlayer = MediaPlayer.create(this, R.raw.do_teen_din_nahi_piya_tha_na);
final Button do_teen_din_nahi_piya_tha_na = (Button) this.findViewById(R.id.do_teen_din_nahi_piya_tha_nado_teen_din_nahi_piya_tha_na);
do_teen_din_nahi_piya_tha_na.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
do_teen_din_nahi_piya_tha_naSoundMediaPlayer.start();
}
});
final MediaPlayer marjaungaSoundMediaPlayer = MediaPlayer.create(this, R.raw.marjaunga);
final Button marjaunga = (Button) this.findViewById(R.id.marjaunga);
marjaunga.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
marjaungaSoundMediaPlayer.start();
}
});
final MediaPlayer bindassSoundMediaPlayer = MediaPlayer.create(this, R.raw.bindass);
final Button bindass = (Button) this.findViewById(R.id.bindass);
bindass.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bindassSoundMediaPlayer.start();
}
});
final MediaPlayer aap_bhi_laga_ke_dekhiyeMediaPlayer = MediaPlayer.create(this, R.raw.aap_bhi_laga_ke_dekhiye);
final Button aap_bhi_laga_ke_dekhiye = (Button) this.findViewById(R.id.aap_bhi_laga_ke_dekhiye);
aap_bhi_laga_ke_dekhiye.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
aap_bhi_laga_ke_dekhiyeMediaPlayer.start();
}
});
final MediaPlayer shuruwatSoundMediaPlayer = MediaPlayer.create(this, R.raw.shuruwat);
final Button shuruwat = (Button) this.findViewById(R.id.shuruwat);
shuruwat.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
shuruwatSoundMediaPlayer.start();
}
});
final MediaPlayer saluchanSoundMediaPlayer = MediaPlayer.create(this, R.raw.saluchan);
final Button saluchan = (Button) this.findViewById(R.id.saluchan);
saluchan.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
saluchanSoundMediaPlayer.start();
}
});
final MediaPlayer bidi_pita_hoon_remixSoundMediaPlayer = MediaPlayer.create(this, R.raw.bidi_pita_hoon_remix);
final Button bidi_pita_hoon_remix = (Button) this.findViewById(R.id.bidi_pita_hoon_remix);
bidi_pita_hoon_remix.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
bidi_pita_hoon_remixSoundMediaPlayer.start();
}
});
final MediaPlayer maza_aata_raat_mein_nind_aatiSoundMediaPlayer = MediaPlayer.create(this, R.raw.maza_aata_raat_mein_nind_aati);
final Button maza_aata_raat_mein_nind_aati = (Button) this.findViewById(R.id.maza_aata_raat_mein_nind_aati);
maza_aata_raat_mein_nind_aati.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
maza_aata_raat_mein_nind_aatiSoundMediaPlayer.start();
}
});
final MediaPlayer aise_hota_hai_bohot_bhayankarSoundMediaPlayer = MediaPlayer.create(this, R.raw.aise_hota_hai_bohot_bhayankar);
final Button aise_hota_hai_bohot_bhayankar = (Button) this.findViewById(R.id.aise_hota_hai_bohot_bhayankar);
aise_hota_hai_bohot_bhayankar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
aise_hota_hai_bohot_bhayankarSoundMediaPlayer.start();
}
});
final MediaPlayer try_karke_dekhiyeSoundMediaPlayer = MediaPlayer.create(this, R.raw.try_karke_dekhiye);
final Button try_karke_dekhiye = (Button) this.findViewById(R.id.try_karke_dekhiye);
try_karke_dekhiye.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try_karke_dekhiyeSoundMediaPlayer.start();
}
});
final MediaPlayer nahi_piyunga_na_toh_khoon_ki_ultiSoundMediaPlayer = MediaPlayer.create(this, R.raw.nahi_piyunga_na_toh_khoon_ki_ulti);
final Button nahi_piyunga_na_toh_khoon_ki_ulti = (Button) this.findViewById(R.id.nahi_piyunga_na_toh_khoon_ki_ulti);
nahi_piyunga_na_toh_khoon_ki_ulti.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
nahi_piyunga_na_toh_khoon_ki_ultiSoundMediaPlayer.start();
}
});
}
}