Package ru.vagrant_ai.questionmarkgame.util

Source Code of ru.vagrant_ai.questionmarkgame.util.Sound

package ru.vagrant_ai.questionmarkgame.util;

import java.io.IOException;

import org.newdawn.slick.openal.Audio;
import org.newdawn.slick.openal.AudioLoader;
import org.newdawn.slick.openal.SoundStore;
import org.newdawn.slick.util.ResourceLoader;

public class Sound {

  private Audio beat_loop;
  private float volume = 1;
  public boolean mute = false;
 
  public Sound()
  {
    beat_loop = loadAudio("beat_loop");
  }

  public Audio loadAudio(String s)
  {
    Audio audio = null;
    try {
      audio = AudioLoader.getAudio("OGG", ResourceLoader.getResourceAsStream("res/audio/"+s+".ogg"));
    } catch (IOException e) {}
    return audio;
  }
 
  public void update()
  {
    SoundStore.get().poll(0);
  }
 
 
  public void playAudio(String s, boolean loop)
  {
    switch(s)
    {
    case "beat_loop":
      beat_loop.playAsSoundEffect(1.0f, 1.0f, true);
      break;
    }
  }
 
  public void stopAudio(String s)
  {
    switch(s)
    {
    case "beat_loop":
      beat_loop.stop();
      break;
    }
  }
 
  public void muteSound()
  {
    if (mute)
    {
      mute = false;
      SoundStore.get().setSoundVolume(volume);
    }
    else
    {
      mute = true;
      volume = SoundStore.get().getSoundVolume();
      SoundStore.get().setSoundVolume(0);
    }
  }
 
  public void setVolume(float f)
  {
    SoundStore.get().setSoundVolume(f);
  }
}
TOP

Related Classes of ru.vagrant_ai.questionmarkgame.util.Sound

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.