我成功地在我的应用程序中添加了背景音乐,但是当我关闭它时,它并没有停止。当我点击 HOME
或者 BACK
按钮时,它仍然播放音乐。有人知道如何解决这个问题吗?
MediaPlayer bsound;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main_menu);
MediaPlayer 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);
}
public void list(View view) {
Intent intent = new Intent(this, Menus.class);
startActivity(intent);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main_menu, menu);
return true;
}