Package com.svanloon.common.music

Source Code of com.svanloon.common.music.WavePlayer

package com.svanloon.common.music;

import java.io.IOException;
import java.net.URL;

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

import com.svanloon.common.util.UrlUtil;

/**
*
* Document the  class
*
* @author svanloon
* @version $Rev$, $LastChangedDate$
*/
public class WavePlayer
  /**
   * Constructs a new <code>WavePlayer</code> object.
   */
  public WavePlayer() {
    super();
  }

  /**
   *
   * Document the play method
   * @param fileName
   * @throws IOException
   * @throws UnsupportedAudioFileException
   * @throws LineUnavailableException
   *
   */
  public void play(String fileName) throws UnsupportedAudioFileException, IOException, LineUnavailableException {
    URL url = new UrlUtil().getUrl(fileName);
    AudioInputStream stream = AudioSystem.getAudioInputStream(url);     
    AudioFormat format = stream.getFormat();
    DataLine.Info info = new DataLine.Info(Clip.class, format);     
    Clip clip = (Clip) AudioSystem.getLine(info);        
    clip.open(stream);     
    clip.start();
  }
}

TOP

Related Classes of com.svanloon.common.music.WavePlayer

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.