Package org.one.stone.soup.core

Source Code of org.one.stone.soup.core.SoundHelper

package org.one.stone.soup.core;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;

public class SoundHelper {

  public static Map<String,AudioInputStream> sounds = new HashMap<String,AudioInputStream>();
 
  public static void addSound(String alias,String fileName) throws LineUnavailableException, UnsupportedAudioFileException, IOException {
            AudioInputStream audioInputStream = AudioSystem.getAudioInputStream( new File(fileName) );
            sounds.put(alias,audioInputStream);
  }
 
  public static void playSound(String alias) throws LineUnavailableException, IOException {
    AudioInputStream audioInputStream = sounds.get(alias);
    Clip clip = AudioSystem.getClip();
    clip.open(audioInputStream);
   
  }
}
TOP

Related Classes of org.one.stone.soup.core.SoundHelper

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.