Android Open Source - SCBIO-OneButtonLarry Music Manager






From Project

Back to project page SCBIO-OneButtonLarry.

License

The source code is released under:

MIT License

If you think the Android project SCBIO-OneButtonLarry listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.scbio.onebuttonlarry;
/*from w  w  w.  j  a v  a2s.  c om*/
import android.content.Context;
import android.media.MediaPlayer;
import android.util.Log;

public class MusicManager {
  private static final String TAG = "MusicManager";
  private static MediaPlayer mPlayer;
  
  public static void start(Context context, int resid) 
  {
    if (mPlayer != null) return;

    mPlayer = MediaPlayer.create(context, resid);

    if (mPlayer == null) {
      Log.e(TAG, "MediaPlayer not created");
    } else {
      try {
        mPlayer.setLooping(true);
        mPlayer.start();
      } catch (Exception e) {
        Log.e(TAG, "MediaPlayer chrashed @ start()", e);
      }
    }

    Log.d(TAG, "Background music playing: "+mPlayer.isPlaying());
  }

  public static void pause() 
  {
    if(mPlayer == null) return;

    try {
      if(!mPlayer.isPlaying()) return;
      mPlayer.pause();
    } catch (Exception e) {
      Log.e(TAG, "MediaPlayer chrashed @ pause()", e);
    }  

  }

  public static void resume() 
  {
    if(mPlayer == null) return;

    try {
      if(mPlayer.isPlaying()) return;
      mPlayer.start();
    } catch (Exception e) {
      Log.e(TAG, "MediaPlayer chrashed @ resume()", e);
    }  
  }

  public static void release() 
  {
    if (mPlayer == null) return;
    try {
        if(mPlayer.isPlaying()) 
        {  
          mPlayer.stop();
        }
        mPlayer.reset();
        mPlayer.release();
        mPlayer = null;
      
    } catch (Exception e) {
      Log.e(TAG, "MediaPlayer crashed @ release()", e);
    }
  }
}




Java Source Code List

org.scbio.onebuttonlarry.AboutActivity.java
org.scbio.onebuttonlarry.GameActivity.java
org.scbio.onebuttonlarry.HighscoreActivity.java
org.scbio.onebuttonlarry.HighscoreManager.java
org.scbio.onebuttonlarry.Highscore.java
org.scbio.onebuttonlarry.MainActivity.java
org.scbio.onebuttonlarry.MusicManager.java
org.scbio.onebuttonlarry.PreferencesManager.java
org.scbio.onebuttonlarry.ResultActivity.java
org.scbio.onebuttonlarry.game.GameStage.java
org.scbio.onebuttonlarry.game.GameView.java
org.scbio.onebuttonlarry.game.Larry.java
org.scbio.onebuttonlarry.game.Sprite.java
org.scbio.onebuttonlarry.stage.GapJumpStage.java
org.scbio.onebuttonlarry.stage.PlatformsStage.java
org.scbio.onebuttonlarry.stage.RockStage.java
org.scbio.onebuttonlarry.stage.RunStopStage.java