1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
| class Son{
private String url;
private Clip clip;
public Son(String s){
url = s;
try{
File fichier = new File(url);
AudioInputStream stream = AudioSystem.getAudioInputStream(fichier);
AudioFormat format = stream.getFormat();
DataLine.Info info = new DataLine.Info(
Clip.class, stream.getFormat(), ((int)stream.getFrameLength()*format.getFrameSize()));
clip = (Clip) AudioSystem.getLine(info);
clip.open(stream);
}catch(UnsupportedAudioFileException uafe){uafe.printStackTrace();
}catch(IOException ioe){ioe.printStackTrace();
}catch (Exception e) {e.printStackTrace();}
}
public void jouer(){
try{
clip.start();
}catch (Exception e){
e.printStackTrace();
}
}
} |