Android Open Source - BlastWords Sound Manager






From Project

Back to project page BlastWords.

License

The source code is released under:

Apache License

If you think the Android project BlastWords 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

/**
 * BlastWords// w w w . j  ava 2s  .c om
 * SoundManager.java
 * 
 * Created by Lou Foster
 * Copyright Studio332 2013. All rights reserved.
 */
package com.studio332.blastwords.util;

import java.util.HashMap;
import java.util.Map;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.files.FileHandle;
import com.studio332.blastwords.model.BlastWordsGame.Mode;
import com.studio332.blastwords.model.Settings;

public class SoundManager {
   private static final SoundManager instance = new SoundManager();
   private Music currMusic = null;
   private Map<String, Sound> sounds = new HashMap<String, Sound>();

   public static final String PAGE_TURN = "pageturn";
   public static final String CLICK = "click";
   public static final String TILE_CLICK = "clack";
   public static final String GLASS = "glass";
   public static final String SELECT_TILE = "select";
   public static final String NO_SWAP = "noswap";
   public static final String NOT_WORD = "notword";
   public static final String BLAST = "blast";
   public static final String TICK = "tick";
   public static final String RING = "ring";
   public static final String WARN = "warn";
   public static final String HI_SCORE = "hiscore";


   public static SoundManager instance() {
      return SoundManager.instance;
   }

   public void init() {
      FileHandle soundFile = Gdx.files.internal("sound/pageturn.mp3");
      this.sounds.put(PAGE_TURN, Gdx.audio.newSound(soundFile));
      soundFile = Gdx.files.internal("sound/menu_click.mp3");
      this.sounds.put(CLICK, Gdx.audio.newSound(soundFile));
      soundFile = Gdx.files.internal("sound/clack.mp3");
      this.sounds.put(TILE_CLICK, Gdx.audio.newSound(soundFile));
      soundFile = Gdx.files.internal("sound/glass.mp3");
      this.sounds.put(GLASS, Gdx.audio.newSound(soundFile));
      soundFile = Gdx.files.internal("sound/select.mp3");
      this.sounds.put(SELECT_TILE, Gdx.audio.newSound(soundFile));
      soundFile = Gdx.files.internal("sound/no_swap.mp3");
      this.sounds.put(NO_SWAP, Gdx.audio.newSound(soundFile));
      soundFile = Gdx.files.internal("sound/not_word.mp3");
      this.sounds.put(NOT_WORD, Gdx.audio.newSound(soundFile));
      soundFile = Gdx.files.internal("sound/blast.mp3");
      this.sounds.put(BLAST, Gdx.audio.newSound(soundFile));
      soundFile = Gdx.files.internal("sound/ticking.mp3");
      this.sounds.put(TICK, Gdx.audio.newSound(soundFile));
      soundFile = Gdx.files.internal("sound/ring.mp3");
      this.sounds.put(RING, Gdx.audio.newSound(soundFile));
      soundFile = Gdx.files.internal("sound/alert.mp3");
      this.sounds.put(WARN, Gdx.audio.newSound(soundFile));
      soundFile = Gdx.files.internal("sound/new_hi_score.mp3");
      this.sounds.put(HI_SCORE, Gdx.audio.newSound(soundFile));
   }

   public void playMenuMusic() {
      if (Settings.instance().isMusicOn() == false) {
         return;
      }

      if (this.currMusic != null ) {
         this.currMusic.stop();
         this.currMusic.dispose();
      }

      this.currMusic = Gdx.audio.newMusic(Gdx.files.internal("sound/menu_music.ogg"));
      this.currMusic.setLooping(true);
      this.currMusic.play();
   }

   public void stopMusic() {
      if (this.currMusic != null) {
         this.currMusic.stop();
         this.currMusic.dispose();
         this.currMusic = null;
      }
   }

   public void playGameMusic(Mode mode) {
      if (Settings.instance().isMusicOn() == false) {
         return;
      }
      
      if (this.currMusic != null && this.currMusic.isPlaying()) {
         this.currMusic.stop();
         this.currMusic.dispose();
      }
      
      String musicFile = "sound/game_music.ogg";
      if ( mode.equals(Mode.CLEAR) ) {
         musicFile = "sound/game_music_clear.ogg";
      } 
      this.currMusic = Gdx.audio.newMusic(Gdx.files.internal(musicFile));
      this.currMusic.setLooping(true);
      this.currMusic.play();
   }
   
   public void pause() {
      if ( this.currMusic != null ) {
         this.currMusic.pause();
      }
   }
   
   public void resume() {
      if ( this.currMusic != null ) {
         this.currMusic.play();
      }
   }

   public void playSound(final String sound) {
      if (Settings.instance().isSoundOn()) {
         Sound s = this.sounds.get(sound);
         if (s != null) {
            s.play();
         }
      }
   }
}




Java Source Code List

com.studio332.blastwords.BlastWords.java
com.studio332.blastwords.MainActivity.java
com.studio332.blastwords.Main.java
com.studio332.blastwords.model.BlastWordsGame.java
com.studio332.blastwords.model.LetterInfo.java
com.studio332.blastwords.model.Settings.java
com.studio332.blastwords.objects.Blaster.java
com.studio332.blastwords.objects.Bomb.java
com.studio332.blastwords.objects.Digit.java
com.studio332.blastwords.objects.GameTimer.java
com.studio332.blastwords.objects.ScoreBoard.java
com.studio332.blastwords.objects.Tile.java
com.studio332.blastwords.screens.AbstractScreen.java
com.studio332.blastwords.screens.GameOver.java
com.studio332.blastwords.screens.GameScreen.java
com.studio332.blastwords.screens.GameStateListener.java
com.studio332.blastwords.screens.MainMenuScreen.java
com.studio332.blastwords.screens.Popup.java
com.studio332.blastwords.screens.SplashScreen.java
com.studio332.blastwords.util.Assets.java
com.studio332.blastwords.util.BlastWordsActions.java
com.studio332.blastwords.util.Overlay.java
com.studio332.blastwords.util.ParticleEffectActor.java
com.studio332.blastwords.util.SoundManager.java