Is there a way to stop all MediaPlayers?

All your problems with Audio, Video and Images.

Is there a way to stop all MediaPlayers?

Postby Niyazi » Mon Dec 28, 2009 4:42 pm

Hi Everyone,

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:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. import android.app.Activity;
  2.  
  3. import android.media.MediaPlayer;
  4.  
  5. import android.os.Bundle;
  6.  
  7. import android.view.View;
  8.  
  9.  
  10.  
  11. public class PlayRingSounds extends Activity {
  12.  
  13.  
  14.  
  15. @Override
  16.  
  17. public void onCreate(Bundle savedInstanceState) {
  18.  
  19.   super.onCreate(savedInstanceState);
  20.  
  21.   setContentView(R.layout.main);
  22.  
  23. }
  24.  
  25.  
  26.  
  27. public void PlayRingFile(View view) {      
  28.  
  29.   switch (view.getId()) {
  30.  
  31.     case R.id.Button01:
  32.  
  33.       MediaPlayer mp1 = MediaPlayer.create(this.getApplicationContext(), R.raw.aaa);
  34.  
  35.       mp1.start();
  36.  
  37.       break;
  38.  
  39.     case R.id.Button02:
  40.  
  41.       MediaPlayer mp2 = MediaPlayer.create(this.getApplicationContext(), R.raw.bbb);
  42.  
  43.       mp2.start();
  44.  
  45.       break;        
  46.  
  47.   }
  48.  
  49. }  
  50.  
  51. }
Parsed in 0.034 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.
Niyazi Cakmak
Niyazi
Freshman
Freshman
 
Posts: 2
Joined: Mon Dec 28, 2009 4:06 pm

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 14 guests