mercredi 11 février 2015

audioInputStream can't be opened in java

I am trying the following code to play an mp3. The file is in the correct folder. An exception is thrown when opening the file.


Any ideas what could be wrong?



String soundFile = "./data/1.mp3";
AudioInputStream audioInputStream = null;

try {
audioInputStream =
AudioSystem.getAudioInputStream(
this.getClass().getResource(soundFile));
}
catch(Exception ex) {System.out.print("exception opening file");}
try{
Clip clip = AudioSystem.getClip();
clip.open(audioInputStream);
clip.start();
}
catch(Exception ex)
{
System.out.print("exception mediaplayer");
}
}


//


Aucun commentaire:

Enregistrer un commentaire