Bonjour, je veux jouer un son dans une JFrame et j'ai trouvé ce code. Seulement il me dit qu'il ne sait pas ouvrir l'input stream
Pouvez-vous me dire pourquoi? Mon son est en *.wav
Voici le code :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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(); } } }
Partager