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(a s);
// 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(a s);
}
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
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(a
// 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(a
}
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
For mp3's you'll need to get an mp3 decoder
By default Java supports AIFF, AU, WAV and MIDI
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.toS tring());
}
}
Thanks
David
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.toS
}
}
Thanks
David
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
try:
AudioClip clip = Applet.getAudioClip(new File("Beat2.WAV").toURL()) ;
clip.loop();
AudioClip clip = Applet.getAudioClip(new File("Beat2.WAV").toURL())
clip.loop();
ASKER
appletts and applications use different methods when calling though. This is a pure application.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.