java - How to get/call the path for a .wav in a resource file -
ok have .wav in resource file made called sound. path file name want /music/sound/one.wav . tried replace path had old path had when didn't have in resource file. want way can create jar file , have people play it. code part have is:
public class al implements actionlistener { @override public void actionperformed(actionevent e) { // todo auto-generated method stub inputstream in; seek { string wav = "c:\\users\\mike\\workspace\\music\\sound\\one.wav"; in = new fileinputstream(wav); audiostream sound = new audiostream(in); audioplayer.player.start(audio); } grab (ioexception e1) { // todo auto-generated grab block e1.printstacktrace(); }}} i have been reading around , way class , resource had no luck. help great, in advance.
try doing
try (inputstream in = this.getclass().getresourceasstream("sound/one.wav")) { if (in != null) { audiostream sound = new audiostream(in); audioplayer.player.start(audio); } } or maybe "one.wav", depending on how set classpath. since in eclipse, want sound source directory. when migrate jar, create sure either contains sound/one.wav or one.wav in path.
java audio resources
No comments:
Post a Comment