I am currently developing my first Android application by reading Dev Documentation at Android official website. What I am trying to accomplish is to play some ring sounds. A section from my code is:
Using java Syntax Highlighting
- import android.app.Activity;
- import android.media.MediaPlayer;
- import android.os.Bundle;
- import android.view.View;
- public class PlayRingSounds extends Activity {
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- }
- public void PlayRingFile(View view) {
- switch (view.getId()) {
- case R.id.Button01:
- MediaPlayer mp1 = MediaPlayer.create(this.getApplicationContext(), R.raw.aaa);
- mp1.start();
- break;
- case R.id.Button02:
- MediaPlayer mp2 = MediaPlayer.create(this.getApplicationContext(), R.raw.bbb);
- mp2.start();
- break;
- }
- }
- }
Parsed in 0.033 seconds, using GeSHi 1.0.8.4
The problem is when I click the 2nd button while "aaa" (sound file from 1st button) is playing, "bbb" also starts playing at the same time. Is there a way to stop "aaa" before "bbb" plays, or is there a way to stop all media players?
Thank you.


