title: static media player object access for resource file in entire application
body: <p>hello  i am new in android development ,in my application i created one class Music to access media Player each and every activity.i have around 50 activities.
  MY Music class Have static media Player object. 
  each activity have next button and forward button.on click of next button there is one static counter that will increase as per the click.each counter value have different song.
  so i want to stop first counter value song  and start next one.on forward same must be done.</p>
  
  <p>anyone have idea , how to implement static method which stop first song and start next one.</p>
  
  <p>here is my code.</p>
  
  <pre><code>public class Music extends Application implements OnCompletionListener    {
  
  
  
     public static   MediaPlayer mp=null;
  
  public static void playGeneric(int name, final ImageButton button,final ImageButton pervious,Context context) {
          button.setEnabled(false);
          button.setClickable(false);
          pervious.setEnabled(false);
          pervious.setClickable(false);
              try{
  
                  mp = MediaPlayer.create(context, name); // used to re-initialze the mediaplayer for reuse since resources were released.
  
                      mp.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
                          @Override
                          public void onPrepared(MediaPlayer arg0) {
  
                              mp.start();
  
                          }
  
                      });
  
                mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
  
                      @Override
                      public void onCompletion(MediaPlayer mp) {
                          // TODO Auto-generated method stub
                          mp.release();
                          System.out.println("Object released");
                          button.setEnabled(true);
                          button.setClickable(true);
                          pervious.setEnabled(true);
                          pervious.setClickable(true);
                      }
                  });
  
  
  
  
          } catch (IllegalStateException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }catch (SecurityException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
              e.getMessage();
          } catch (NullPointerException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
              e.getMessage();
          }
  
      }
  
   public static void stopplaying() {
      if (mp != null) {
          mp.stop();
          mp.release();
          mp = null;
      }
  
  }
  }
  </code></pre>
  
  <p>on activity on next button click static counter increment</p>
  
  <pre><code>    if (v == next) {
         counter++
  
   if (counter == 1) {
              Log.i("counter", "value :: " + counter);
              Music.playGeneric(audio, next,pervious, getBaseContext());
  
          }
  
  
       if (counter == 2) {
                     Music.playGeneric(audio, next,pervious, getBaseContext());                
  }
  
      ....................................
            if(counter==25){}
      }
  </code></pre>
  
  <blockquote>
    <p>like this way. now i want to stop music , how to stop it? please help
    me.</p>
  </blockquote>