Java Sound Pay Code

From Simson Garfinkel
Jump to navigationJump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
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 Sampled {  
    public static void main(String[] args) {    
	try{      
	    AudioInputStream stream        = AudioSystem.getAudioInputStream(new File(args[0]));      
	    AudioFormat format = stream.getFormat();      
	    DataLine.Info info = new DataLine.Info(Clip.class, stream.getFormat());      
	    Clip clip = (Clip) AudioSystem.getLine(info);         
	    clip.open(stream);      
	    clip.start();
	} catch (Exception e)	{      
	    e.printStackTrace();    
	}  
    }
}