Android Open Source - square-libgdx Sound Manager






From Project

Back to project page square-libgdx.

License

The source code is released under:

GNU General Public License

If you think the Android project square-libgdx 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.denzyldick.square;
//from   w w w  .  j  a v a2 s . c o m
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;

public class SoundManager extends Sprite {
  Texture volumeOn, volumeOff;
  public static Sprite volumeSprite;

  Sound buttonClick, failureEffect, succesEffect, objectEffect;
  Music musicLoop;
  Preferences volumeData;

  public void draw(SpriteBatch spritebatch) {
    spritebatch.draw(volumeSprite, 0, 0);

  }
   protected Preferences getPrefs() {
        if(volumeData==null){
           volumeData = Gdx.app.getPreferences("volume");
        }
     return volumeData;
     }

  public float getVolume() {
    return volumeData.getFloat("volume");
  }

  public SoundManager() {
    getPrefs();
    if (volumeData.contains("volume") == false) {
      volumeData.putFloat("volume", 1f);
    }
    volumeOn = new Texture("ui/volumeon.png");
    volumeOff = new Texture("ui/volumeoff.png");

    if (volumeData.getFloat("volume") == 1) {
      volumeSprite = new Sprite(volumeOn);
    } else {
      volumeSprite = new Sprite(volumeOff);
    }

    buttonClick = Gdx.audio.newSound(Gdx.files
        .internal("sounds/menuclick.ogg"));
    musicLoop = Gdx.audio.newMusic(Gdx.files
        .internal("sounds/musicloop1.ogg"));
    failureEffect = Gdx.audio.newSound(Gdx.files
        .internal("sounds/failure.ogg"));
    succesEffect = Gdx.audio.newSound(Gdx.files
        .internal("sounds/succes.ogg"));
    objectEffect = Gdx.audio.newSound(Gdx.files
        .internal("sounds/object.ogg"));
    volumeData.flush();
  }

  public void buttonClick() {
    buttonClick.play(volumeData.getFloat("volume"));

  }

  public void musicLoop() {
    musicLoop.play();
    musicLoop.setVolume(volumeData.getFloat("volume"));
    musicLoop.setLooping(true);

  }

  public void musicLoopEnd() {
    musicLoop.stop();
  }

  public void failureSound() {
    failureEffect.play(volumeData.getFloat("volume"));

  }

  public void succeedEffect() {

    succesEffect.play(volumeData.getFloat("volume"));

  }

  public void objectEffect() {
    objectEffect.play(volumeData.getFloat("volume"));
  }

  public void muteVolume() {
    volumeData.putFloat("volume", 0f);
    volumeData.flush();
  }

  public void unmuteVolume() {
    volumeData.putFloat("volume", 1f);
    volumeData.flush();
  }
}




Java Source Code List

actors.Square.java
com.denzyldick.square.Assets.java
com.denzyldick.square.BackgroundAnimation.java
com.denzyldick.square.File.java
com.denzyldick.square.Font.java
com.denzyldick.square.Main.java
com.denzyldick.square.SoundManager.java
com.denzyldick.square.SquareMain.java
com.denzyldick.square.StarManagement.java
com.denzyldick.square.client.GwtLauncher.java
com.denzyldick.square.json.JsonArray.java
com.denzyldick.square.json.JsonLiteral.java
com.denzyldick.square.json.JsonNumber.java
com.denzyldick.square.json.JsonObject.java
com.denzyldick.square.json.JsonParser.java
com.denzyldick.square.json.JsonString.java
com.denzyldick.square.json.JsonValue.java
com.denzyldick.square.json.JsonWriter.java
com.denzyldick.square.json.ParseException.java
com.realcode.square.MainActivity.java
screens.GameMenu.java
screens.GameScreen.java
screens.LostScreen.java
screens.MenuScreen.java
screens.OptionsScreen.java
screens.SplashScreen.java
screens.TutorialScreen.java
screens.WonScreen.java