audio - Sound not working in Java -
i've been researching sound files in java past couple of days , thought try , sound running.
i coded small segment unfortunately, there no sound played after running it.
there bug somewhere i'm not seeing or code not work. thanks.
import java.applet.applet; import java.applet.audioclip; import java.net.url; public class driver { public static void main ( string [] args ) throws exception { url resourceurl = new url("file:;///c:/users/jack/desktop/pok/pokemon.wav"); final audioclip clip = applet.newaudioclip(resourceurl); clip.loop(); } }
let's start with...
url resourceurl = new url("file:;///c:/users/jack/desktop/pok/pokemon.wav"); apart fact there ; in path doesn't belong, there simpler way generate url file
url url = new file("c:/users/jack/desktop/pok/pokemon.wav").touri().tourl(); then move onto this...
final audioclip clip = applet.newaudioclip(resourceurl); looking @ code, program isn't applet, shouldn't using applet based methods.
for better ways, start taking @ sound tutorial
which might more like...
url url = new file("c:/users/jack/desktop/pok/pokemon.wav").touri().tourl(); audioinputstream ais = audiosystem.getaudioinputstream(url)); clip clip = audiosystem.getclip(); clip.open(ais); clip.start(); clip.drain(); // stop main thread exiting
Comments
Post a Comment