Jouer un son wav: Requested buffer too large.
Bonjour,
Je joue quelques sons sur une application JAVA, si les fichiers sont petits ça passe mais si le fichier est plus volumineux voilà l'erreur que j'ai: javax.sound.sampled.LineUnavailableException: Failed to allocate clip data: Requested buffer too large.
Voilà mon code:
Code:
1 2
| JavaSound sonFond = new JavaSound(new File("sons/Metal_Slug_5_-_Final_Attack_Soundtrack.wav"));
sonFond.playFile(); |
Code:
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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| public class JavaSound {
/*
* File
*/
File fichier;
/**
* TODO commenter le rôle de l'état initial atteind
* @param fichier
*/
public JavaSound(File fichier) {
this.fichier = fichier;
}
public void playFile() {
AudioInputStream sound;
try {
sound = AudioSystem.getAudioInputStream(fichier);
// load the sound into memory (a Clip)
DataLine.Info info = new DataLine.Info(Clip.class, sound.getFormat());
Clip clip;
try {
clip = (Clip) AudioSystem.getLine(info);
clip.open(sound);
// due to bug in Java Sound, explicitly exit the VM when
// the sound has stopped.
clip.addLineListener(new LineListener() {
public void update(LineEvent event) {
if (event.getType() == LineEvent.Type.STOP) {
event.getLine().close();
}
}
});
// play the sound clip
clip.start();
} catch (LineUnavailableException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (UnsupportedAudioFileException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} |
Merci!