Try to pause and resume MediaPlayer:
MediaPlayer bsound;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_menu);
bsound = MediaPlayer.create(this, R.raw.sample);
bsound.setLooping(true); // Set looping
bsound.setVolume(100, 100);
bsound.start();
TextView txt = (TextView) findViewById(R.id.textView1);
Typeface font = Typeface.createFromAsset(this.getAssets(), "Schalk.ttf");
txt.setTypeface(font);
TextView txt1 = (TextView) findViewById(R.id.button1);
Typeface font1 = Typeface.createFromAsset(this.getAssets(), "Schalk.ttf");
txt1.setTypeface(font1);
}
@Override
protected void onPause() {
if (bsound.isPlaying()) {
bsound.pause();
}
super.onPause();
}
@Override
protected void onResume() {
super.onResume();
bsound.start();
}
And yes, you didn't initialize that MediaPlayer bsound
field. Change this line:
MediaPlayer bsound = MediaPlayer.create(this, R.raw.sample);
to this:
bsound = MediaPlayer.create(this, R.raw.sample);