Bonjour à tous, dans le cadre d'un projet perso, j'ai une classe qui me pose probleme:
En fait, elle marche tres bien sur Eclipse (diffusion de son) mais lorsque j'exporte le jar pour l'executer avec javaw sous windows, le son ne se lance pas.
J'ai eu le meme probleme un certain moment avec une image qui ne s'affichait que sur eclipse, et pour corriger ca, j'ai mis cette ligne:

java.net.URL url = gimageban = new JLabel(new ImageIcon(url));etClass().getResource("ban.png");

Je vous met le code de la classe qui me pose probleme...

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
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
 
import java.io.*;
import javax.sound.sampled.*;
 
 
public class Sound 
{
	private AudioFormat format;
	private byte[] samples;
 
	public Sound(String filename){
		try{
			AudioInputStream stream = AudioSystem.getAudioInputStream(new File(filename));
			format = stream.getFormat();
			samples = getSamples(stream);
		}
		catch (UnsupportedAudioFileException e){
			e.printStackTrace();
		}
		catch (IOException e){
			e.printStackTrace();
		}
	}
 
	public byte[] getSamples(){
		return samples;
	}
 
	public byte[] getSamples(AudioInputStream stream){
		int length = (int)(stream.getFrameLength() * format.getFrameSize());
		byte[] samples = new byte[length];
		DataInputStream in = new DataInputStream(stream);
		try{
			in.readFully(samples);
		}
		catch (IOException e){
			e.printStackTrace();
		}
		return samples;
	}
 
 
	public void play(InputStream source){
		// 100 ms buffer for real time change to the Sound stream
		int bufferSize = format.getFrameSize() * Math.round(format.getSampleRate() / 10);
		byte[] buffer = new byte[bufferSize];
		SourceDataLine line;
		try{
			DataLine.Info info = new DataLine.Info(SourceDataLine.class, format);
			line = (SourceDataLine)AudioSystem.getLine(info);
			line.open(format, bufferSize);
		}
		catch (LineUnavailableException e){
			e.printStackTrace();
			return;
		}
		line.start();
		try{
			int numBytesRead = 0;
			while (numBytesRead != -1){
				numBytesRead = source.read(buffer, 0, buffer.length);
				if (numBytesRead != -1)
					line.write(buffer, 0, numBytesRead);
			}
		}
		catch (IOException e){
			e.printStackTrace();
		}
		line.drain();
		line.close();
	}
 
	public static void main(String[] args){
		String url = "notify.wav";
		Sound player = new Sound(url);
		InputStream stream = new ByteArrayInputStream(player.getSamples());
		player.play(stream);
		System.exit(0);
	}
}
Merci pour votre aide

Titip