my java progeam run 100% if i run it from the compiler netbeans put if i run it from file manager its will be in dist folder inside the project (the program have a button that run wav file) the button have a catch ioexception if i run it from compiler the sound will run put if i run it from dist folder or move then run it to any path the catch that have the ioexception as a parameter will excecute i used audioSystem and cought it with a Clip class so if any exception occure in the first way the Clip class will try to run the sound file. code:
public void getSoundData(int delay){
ActionListener taskPerformer = new ActionListener(){
@Override
public void actionPerformed(ActionEvent evt){
try{
int random=(int)(Math.random()*12+1);
InputStream input = new FileInputStream("src/azcar/sounds/"+String.valueOf(random)+".wav");
AudioStream audio = new AudioStream(input);
AudioPlayer.player.start(audio);
} catch (Exception exc) {
try {
Clip clip = AudioSystem.getClip();
int random=(int)(Math.random()*12+1);
AudioInputStream input = AudioSystem.getAudioInputStream(new File("src/azcar/sounds/"+String.valueOf(random)+".wav"));
clip.open(input);
clip.start();
} catch (LineUnavailableException ex) {
JOptionPane.showMessageDialog(null, ex);
} catch (UnsupportedAudioFileException ex) {
JOptionPane.showMessageDialog(null, "نوع ملفات الصوت غير مدعوم");
} catch (IOException ex) {
JOptionPane.showMessageDialog(null, "لم أتمكن من االوصول لملفات الصوت");
}
}
}
};
Timer timer = new Timer(delay*1000*60,taskPerformer);
timer.setRepeats(true);
timer.start();
}