0

I want to add a sound in a frame I made. I googled it and I found that Java doesn't support mp3 so I converted a song in my disk to a wav file. After impoting sun.audio.* and java.io.* in my project, I add these lines in the frame constructor

    File xx = new File("C:\\Users\\LENOVO\\Desktop\\oss.wav");
    InputStream in = new FileInputStream(xx);
    AudioStream as = new AudioStream(in); 
    AudioPlayer.player.start(as);

but it doesn't work, I'm not sure what is the problem and I hope someone of you can help me to figure it out.

Abdelaziz Dabebi
  • 1,624
  • 1
  • 16
  • 21
  • I'm beginner here, here is the error message: Unhandled exception type FileNotFoundException Access restriction: The type 'AudioStream' is not API (restriction on required library 'C:\Program Files\Java\jre7\lib\rt.jar') and few other lines – Abdelaziz Dabebi Jul 10 '14 at 01:02
  • Can you post the full exception stack trace within your answer? Use the __edit__ feature. Thanks. :) – Unihedron Jul 10 '14 at 01:04
  • the error message is too long,, here it is: https://fbcdn-sphotos-g-a.akamaihd.net/hphotos-ak-xfp1/v/t1.0-9/10552402_312115595619279_6152313424296453681_n.jpg?oh=ff1013fa17fb0e4b09eb66dcb9accefc&oe=5433E9DD&__gda__=1413071188_d55a02c5c4843ce5e103f82d8eaca455 – Abdelaziz Dabebi Jul 10 '14 at 01:06
  • 2
    For [example](http://stackoverflow.com/questions/21146973/starting-and-stopping-music-in-background/21147304#21147304) – MadProgrammer Jul 10 '14 at 01:08
  • Are you trying to do this from an applet? – MadProgrammer Jul 10 '14 at 01:12
  • **don't post links to off site resources, they good dead and aren't any use to anyone else** post what was asked for here or this will get closed ASAP! –  Jul 10 '14 at 01:29

1 Answers1

1

You receive errors for unresolved compilation errors. You're not handling Checked Exception Types where you should be.

try {
    File xx = new File("C:\\Users\\LENOVO\\Desktop\\oss.wav");
      // Must handle FileNotFoundException from new File()!
    InputStream in = new FileInputStream(xx);
    AudioStream as = new AudioStream(in);
    try {
        AudioPlayer.player.start(as); // Must handle IOException from start()!
    }
    catch (IOException ex) { /* Ignore? */ }
}
catch (FileNotFoundException ex) { /* Ignore? */ }

Read more:

Community
  • 1
  • 1
Unihedron
  • 10,902
  • 13
  • 62
  • 72