java - Sound file not found, not in directory? -


I'm coding it in java and put the voice folder with bgmusic Have given. Wav but there is still no identity in it. Am I doing something wrong?

This is my voice category:

  import java.applet.Applet; Import java.applet.AudioClip; Import java.io.file; Import java.net.MalformedURLException; Public Squared Sound {Private AudioClick MyClip; Public sound (string filename) {try {file file = new file (fileName); If (file.exists ()) {myClip = (AudioClip) applet.nuoudo clip (file.toURI () .toURL ()); } And {new runtime expiry ("sound: file not found:" + fileName); }} Hold (Malformedlexception E) {New Runtime Expansion ("Sound: Distorted URL:" + E); }} Public Zero Play () {myClip.play (); }}   

This is then the form of an object in my second class to run bgmusic.wav :

  string file name Has ran into = "BGMUSIC.WOW"; String Sounder = "." + File. Separator + "sound" + file. Separator; String filePath = soundDir + fileName; Sound bgMusic = new sound (file path); BgMusic.play ();   

If I am not mistaken, then I think everything is set up correctly but I got a sound: file not found: ./sounds/bgmusic.wav which is returned in my voice class with throw exception because I have the sounds folder to ./sounds/bgmusic. Must be correct as the subdirectory of the main Java folder passing through wav ?

new file (".") the base folder of your application (root Folder), so check your directory structure to see where the file is in relation to the file base folder. Otherwise, share your project structure.

If you are putting the file into Java square path (src folder) then you can load the sound file with the class path (reference)

Comments

Popular posts from this blog

c# - passing input text from view to contoller with FacebookContext using Facebook app -

ios - Does Core Data autoupdate a many to many relationship on saving -

Calling a C++ function from C# by passing a string with variable size to it -