Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Page 2 of 2 FirstFirst 12
Results 26 to 31 of 31

Thread: Need help playing sound in backround of a program in a loop.(Please Fix my code!)

  1. #26
    Member DusteroftheCentury's Avatar
    Join Date
    Jan 2012
    Location
    Northern California
    Posts
    42
    My Mood
    Fine
    Thanks
    6
    Thanked 2 Times in 2 Posts

    Default 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.

  2. #27
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default 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:

    testclass.jpg

    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.

  3. #28
    Member DusteroftheCentury's Avatar
    Join Date
    Jan 2012
    Location
    Northern California
    Posts
    42
    My Mood
    Fine
    Thanks
    6
    Thanked 2 Times in 2 Posts

    Default 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.

  4. #29
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default 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.

  5. #30
    Member DusteroftheCentury's Avatar
    Join Date
    Jan 2012
    Location
    Northern California
    Posts
    42
    My Mood
    Fine
    Thanks
    6
    Thanked 2 Times in 2 Posts

    Default 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

  6. #31
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    987
    Thanks
    6
    Thanked 206 Times in 182 Posts

    Default 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.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Adding sound to program.
    By Archibold9 in forum What's Wrong With My Code?
    Replies: 32
    Last Post: December 21st, 2011, 02:28 PM
  2. Error with code to implement sound
    By LukeDavison in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 4th, 2011, 02:27 PM
  3. Playing a .wav file in SplitPaneDemo code
    By elwells in forum What's Wrong With My Code?
    Replies: 0
    Last Post: October 16th, 2011, 11:39 PM
  4. Playing sound in an applet
    By Skyhigh32 in forum Java Theory & Questions
    Replies: 1
    Last Post: June 3rd, 2011, 07:41 AM
  5. playing sound using java
    By sdhilipan89 in forum Java Applets
    Replies: 6
    Last Post: March 25th, 2010, 08:59 AM