Re: Need help playing sound in backround of a program in a loop.(Please Fix my code!)
Thank you so much guys! I tested it on a new .wav file and it does play in a loop! (It is a very short file and after playing more times than I can count, about 3 mins it stopped. Im guessing Java put a restriction on looping it so much. Its only like 2 secs. HOWEVER, with the exact same code, in Eclipse or out, it still does that with the PBnJ.wav file.) Do you guys know a good site for converting mp3's to .wavs without corrupting them? Although interestingly enough the *corrupted* .wav file plays fine in Windows Media Player, just not in Java.
Also I still cant figure out exporting the resources into a runnable jar correctly.
1 Attachment(s)
Re: Need help playing sound in backround of a program in a loop.(Please Fix my code!)
Audacity: Free Audio Editor and Recorder is good and popular almost to the point of being "standard". I used it to construct the wav file I used to test your code.
The location of the two resource files that accompanies the code in #20 looks like this:
Attachment 979
With that set up the application exports as an executable jar OK.
Alternatively you can create the jar file by hand. It takes more work but the process is instructive. Details are at the Packaging Programs in JAR Files section of Oracle's Tutorial.
Re: Need help playing sound in backround of a program in a loop.(Please Fix my code!)
Thanks. Although I dont think the wav file im using is corrupted. It works in any music player, just not using java.
Also, when I try to run the new jar file using the import method to import the files, it does not run at all. It dosent even open. It only opens when I put the resource files in the desktop. Before I download the new program, could you see if you can get my .wav file to work please?
Free File Sharing Made Simple - MediaFire
If not the download link also has the mp3 file so you might be able to convert it yourself.
Re: Need help playing sound in backround of a program in a loop.(Please Fix my code!)
I can confirm that that wav file (with the code in #20) runs fine: ie loops when it gets to the end. This is also true when I export the project as an executable jar and run that.
I don't really know what you mean by "importing" the files. Is this an Eclipse thing? The location of the resources I am using is as pictured in #27. I just drag and dropped them there.
Re: Need help playing sound in backround of a program in a loop.(Please Fix my code!)
Yes, Eclipse makes you do a special import thing rather than just drag and drop.
I am so confused right now. The file acts like it is corrupted. However it is not because it will play in anything else besides Java. Other files loop correctly. The jar file does not even run or open without both resource files in the same folder. I have tried making many versions of the jar file with no success.
I think at this point, I should just try to learn other aspects of Java, when I am more advanced I may come back to this.
Thank you for helping.
-Duster
Re: Need help playing sound in backround of a program in a loop.(Please Fix my code!)
You're welcome.
As you can see from the image I'm using Eclipse and I just drag and drop files into the package view wherever I want them.
You're probably right: get some more straight forward experience under your belt - of both Java and Eclipse - and then come back to the problem. Somewhere above I linked to the section in Oracle's Tutorial about creating jar files. It takes more work this way but I have found that what they say there, and in general being able to build simple applications from the command line, really helps when it comes to understanding all the options presented to you by an IDE like Eclipse.