Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

how can I play a sound in Java?

I want one of my buttons to play a sound, but have no idea where to begin. I have looked at the AudioSystem class but that just makes it more confusing. I just need a way to play my sound. Note- it's in .wav format, I don't know if that affects this process (probably not, but just to be safe).

Update:

wait, nevermind, it's in MP3 format, my bad.

2 Answers

Relevance
  • McFate
    Lv 7
    9 years ago
    Favorite Answer

    Java does not natively support playing of .mp3 files.

    See this link for one way to do it, with an example (but it requires a third-party library):

    http://introcs.cs.princeton.edu/java/faq/mp3/mp3.h...

    If you have only the one sound to play, and it's not very long, then you might consider converting the .mp3 to a .wav and then you CAN use AudioSystem.

    @M

  • ?
    Lv 4
    4 years ago

    you're seeing the "" errors simply by fact Java does not truly comprehend residing house windows paths. you in all probability prefer to transform that to a URL. See the link decrease than for extra information in this. yet greater usually, once you're working an Applet it won't have the means to get admission to your community filesystem. it is by employing layout of the 'sandbox' wherein an Applet runs for risk-free practices reasons. you may get around this by employing signing the Applet or passing it a real information superhighway URL to the clip to play.

Still have questions? Get your answers by asking now.