load Audio Clip - Java javax.sound.sampled

Java examples for javax.sound.sampled:Audio

Description

load Audio Clip

Demo Code


//package com.java2s;
import java.io.File;
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;

public class Main {
    public static void main(String[] argv) throws Exception {
        String path = "java2s.com";
        System.out.println(loadAudio(path));
    }/*www  .ja v  a 2  s.  c o m*/

    public static Clip loadAudio(String path) throws Exception {
        Clip clip = null;

        AudioInputStream stream = AudioSystem.getAudioInputStream(new File(
                path));
        AudioFormat streamFormat = stream.getFormat();
        clip = (Clip) AudioSystem.getLine(new DataLine.Info(Clip.class,
                streamFormat));
        clip.open(stream);
        return clip;
    }
}

Related Tutorials