Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.IOException;
- import java.net.URL;
- 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;
- import javax.swing.JFrame;
- public class SoundClipTest extends JFrame
- {
- // Constructor
- public SoundClipTest() throws LineUnavailableException
- {
- try {
- // Open an audio input stream.
- URL url = this.getClass().getClassLoader().getResource("dog.wav");
- AudioInputStream audioIn = AudioSystem.getAudioInputStream(url);
- // Get a sound clip resource.
- Clip clip = AudioSystem.getClip();
- // Open audio clip and load samples from the audio input stream.
- clip.open(audioIn);
- clip.start();
- }
- catch (UnsupportedAudioFileException e)
- {
- e.printStackTrace();
- }
- catch (IOException e)
- {
- e.printStackTrace();
- }
- catch (LineUnavailableException e)
- {
- e.printStackTrace();
- }
- }
- public static void main(String[] args) throws LineUnavailableException
- {
- new SoundClipTest();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement