Android Open Source - crabox Audio Manager






From Project

Back to project page crabox.

License

The source code is released under:

Apache License

If you think the Android project crabox 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 com.costular.crabox.util;
//w w  w. jav a  2  s.co m
import com.badlogic.gdx.audio.Sound;
import com.costular.crabox.Cbx;

public class AudioManager {

  public float musicDefaultVolume;
  public float soundsDefaultVolume;
  
  private boolean canPlay;
  private boolean playingMusic;
  private float musicVolume;
  private float soundsVolume;
  
  public AudioManager() {
    canPlay = Cbx.getPreferences().getSound();
    playingMusic = false;
    
    musicDefaultVolume = 0.7f;
    soundsDefaultVolume = 0.4f;
    
    musicVolume = 0.7f;
    setSoundsVolume(0.4f);
  }
  
  public boolean canPlay() {
    return canPlay;
  }
  public void setCanPlay(boolean canPlay) {
    this.canPlay = canPlay;
  }
  public boolean isPlayingMusic() {
    return playingMusic;
  }
  public void setPlayingMusic(boolean playingMusic) {
    this.playingMusic = playingMusic;
  }

  public float getMusicVolume() {
    return musicVolume;
  }
  public void setMusicVolume(float volume) {
    if(volume > 1) {
      this.musicVolume = 1;
    }
    else if(volume < 0.1) {
      this.musicVolume = 0.1f;
    }else {
      this.musicVolume = volume;
    }
  }

  public float getSoundsVolume() {
    return soundsVolume;
  }

  public void setSoundsVolume(float soundsVolume) {
    this.soundsVolume = soundsVolume;
  }

  public void startMusic() {
    if(!canPlay) {
      return;
    }
    
    if(isPlayingMusic()) {
      Cbx.getResources().music.stop();
    }
    
    if(musicDefaultVolume != musicVolume) {
      musicVolume = musicDefaultVolume;
    }
    
    Cbx.getResources().music.setVolume(musicVolume); // En un futuro ellos elegir?n el volumen.
    Cbx.getResources().music.setLooping(true);
    Cbx.getResources().music.play();
    
    setPlayingMusic(true); // Marcamos que est? sonando la m?sica
  }
  
  public void stopMusic() {    
    Cbx.getResources().music.stop();
    
    //Decir que ya no est? sonando la m?sica
    setPlayingMusic(false);
  }
  
  public void playSound(Sound sound, boolean loop) {
    if(!canPlay) {
      return;
    }
    
    if(sound == null) {
      return;
    }
    
    if(soundsVolume != soundsDefaultVolume) {
      soundsVolume = soundsDefaultVolume;
    }
    
    sound.setLooping(0, loop);
    sound.play(soundsVolume);
  }
  
  public void downMusicToStop() {
    for(int i = 0; i < 10; i++) {
      setMusicVolume(getMusicVolume()-0.1f);
      try {
        Thread.sleep(100);
      } catch (InterruptedException e) {
        e.printStackTrace();
      }
    }
    stopMusic();
  }
  
  public void playJumpSound() {
    playSound(Cbx.getResources().jump, false);
  }
}




Java Source Code List

com.costular.crabox.AddInterface.java
com.costular.crabox.Cbx.java
com.costular.crabox.Controller.java
com.costular.crabox.GameController.java
com.costular.crabox.GameState.java
com.costular.crabox.MainClass.java
com.costular.crabox.actors.Box.java
com.costular.crabox.actors.ContactBodies.java
com.costular.crabox.actors.DefaultBox.java
com.costular.crabox.actors.DefaultTriangle.java
com.costular.crabox.actors.Player.java
com.costular.crabox.actors.Score.java
com.costular.crabox.actors.ToggleButton.java
com.costular.crabox.android.AndroidLauncher.java
com.costular.crabox.android.Facebook.java
com.costular.crabox.android.Notification.java
com.costular.crabox.android.RequestAd.java
com.costular.crabox.screens.GameScreen.java
com.costular.crabox.screens.HUD.java
com.costular.crabox.screens.MenuScreen.java
com.costular.crabox.util.AssetManager.java
com.costular.crabox.util.AudioManager.java
com.costular.crabox.util.Box2DUtils.java
com.costular.crabox.util.FacebookRequest.java
com.costular.crabox.util.GeometryUtils.java
com.costular.crabox.util.NotificationRequest.java
com.costular.crabox.util.Preferences.java
com.costular.crabox.util.StageGenerator.java
com.costular.crabox.util.Utils.java