Link to home
Start Free TrialLog in
Avatar of ildave1
ildave1

asked on

Incorporating Sound

I've been attempting this for a bit now and i'm still a little dissoriented when it comes to implementing sound into a java application (not an applet).

I've found a couple of tutorials, but I may be overlooking/not understanding something.

For example, this looks fairly simple.  (from: http://www.javaworld.com/javaworld/javatips/jw-javatip24.html)

//** add this into your application code as appropriate
// Open an input stream  to the audio file.
InputStream in = new FileInputStream(Filename);
// Create an AudioStream object from the input stream.
AudioStream as = new AudioStream(in);        
// Use the static class member "player" from class AudioPlayer to play
// clip.
AudioPlayer.player.start(as);            
// Similarly, to stop the audio.
AudioPlayer.player.stop(as);

So the way im thinking about this is that i'll create a method inside the splash screen .java file.

public void playTheme()
{    
       InputStream in = new FileInputStream("Binds.WAV");
       AudioStream as = new AudioStream(in);
       AudioPlayer.player.start(as);
}

   And to call it with my window() method id just put in playTheme()?


Does this only work for *.wav?  I found a real nice royalty free music webpage that houses a lot of nice mp3 sounds (http://www.koumis.com/music.htm)


Thanks in advance

Regard,
Dave
Avatar of Mick Barry
Mick Barry
Flag of Australia image

For mp3's you'll need to get an mp3 decoder
By default Java supports AIFF, AU, WAV and MIDI
Avatar of ildave1
ildave1

ASKER

Great... I got this to work.. I actually found an easier way to solve this problem.  I found a MP3 >> WAV converter.

Would it be hard to 'LOOP' this so it continues playing, over and over again?

    public void playTheme()
    {
          AudioPlayer player = AudioPlayer.player;
          try{
                AudioStream audiostr = new AudioStream(new  FileInputStream("Beat2.WAV"));
                player.start(audiostr);
          }
          catch(IOException err){
                System.out.println(err.toString());
          }
    }


Thanks

David
SOLUTION
Avatar of suprapto45
suprapto45
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
try:

AudioClip clip = Applet.getAudioClip(new File("Beat2.WAV").toURL());
clip.loop();

Avatar of ildave1

ASKER

appletts and applications use different methods when calling though.  This is a pure application.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial