java - Sound will not play in JAR file -


i have problem , hope can me. talk doing know what's going on: @ moment i'm trying program litte piece of software can play me music files (mp3 files exact, i'm using jlayer api). i'm working netbeans , have succesfully imported music file in project. if build program , open resulting jar file archive program, can find music file in there. function i'm using goes this:

    public static string play(string file)  {     file test = new file(file);     try {         fileinputstream in = new fileinputstream(test);         player pl = new player(in);         pl.play();         return "success";     }     catch (exception e) {         return e.tostring();     }  } 

as can see i'm getting string path name , refactor him can play file. i'm calling function following code (the music file saved in ressources package):

mp3.play(getclass().getresource("/ressources/angel.mp3").getpath()) 

so if start programm via netbeans works fine. if create jar file , start program nothing happens. exception getting following:

java.io.filenotfoundexception: file:\c:\users\raphael\documents\netbeansprojects\mp3\dist\mp3.jar!\ressources\angel.mp3  

it says file not exist if check jar file there......

another strange thing found out following: if use following function play music file:

    public static string play(inputstream test)  {     try {         player pl = new player(test);         pl.play();         return "success";     }     catch (exception e) {         return e.tostring();     }  } 

and call function following argument:

mp3.play(getclass().getresourceasstream("/ressources/angel.mp3")); 

everything works fine in both netbeans , final jar. can explain me i'm doing wrong , second function works in jar version?

it nice if me in matter.

greetings, xxknightriderxx

i assuming have 2 packages 1 src .java files located , other resources sound files located

so suggest use

mp3.play(getclass().getresourceasstream("/angel.mp3")); 

because getresource() automatically finds resource package


Comments

Popular posts from this blog

dns - How To Use Custom Nameserver On Free Cloudflare? -

python - Pygame screen.blit not working -

c# - Web API response xml language -