Lecture d'un fichier son.. plusieurs fois
Salut !
J'utilise pour mon application cette classe:
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
|
import javax.sound.sampled.*;
import java.io.*;
import java.net.*;
public class Son
{
private String url;
private Clip clip;
public Son(String s)
{
url = s;
try
{
AudioInputStream stream = AudioSystem.getAudioInputStream(new File(url));
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 (Exception e) {}
}
/** * Joue le son associé */
public void jouer()
{
try { clip.start(); }
catch (Exception e) {}
}
} |
qui me permet de lire un fichier son lorsque je clique sur un bouton.
Le problème c'est que cela ne fonctionne qu'une seule fois: si je reclique sur le bouton il ne se passe rien. Savez-vous pourquoi ?
Voici le code de mon ecouteur:
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
|
import java.awt.event.*;
import javax.swing.event.*;
import javax.swing.*;
public class EcouteurCase extends MouseAdapter
{
private Grille GrilleRecup;
private int ValRetour = 0;
private Son son1 = new Son("sons/son1.wav");
private Son son2 = new Son("sons/son2.wav");
private Son son3 = new Son("sons/son3.wav");
EcouteurCase(Grille g)
{
this.GrilleRecup = g;
}
public void mouseClicked(MouseEvent e)
{
ValRetour = GrilleRecup.QuelSon();
switch(ValRetour)
{
case 1: son1.jouer();
break;
case 2: son2.jouer();
break;
case 3: son3.jouer();
break;
}
}
} |
Merci, @+