No, probably not.
There's java.applet.AudioClip, but that's so basic as to be hardly worth it.
Otherwise this is about as simple as I could make it...
Clip clip = null;
AudioInputStream in = null;
try
{
InputStream tmp = .... // get the plain input stream from wherever
if(tmp != null)
{
in = AudioSystem.getAudioInputStream(tmp);
DataLine.Info clipInfo = new DataLine.Info(Clip.class, in.getFormat());
if(AudioSystem.isLineSupported(clipInfo))
{
clip = (Clip)AudioSystem.getLine(clipInfo);
clip.open(in);
}
}
}
catch(UnsupportedAudioFileException e)
{
System.err.println("Audio file format not supported.");
}
catch(LineUnavailableException e)
{
System.err.println("Audio clip not available.");
}
catch(IOException e)
{
System.err.println("Error creating audio clip.");
}
finally
{
closeStream(in);
}
clip.setFramePosition(0); // rewind, in case it's been played before
clip.loop(0); // play and loop X times
Sound is one of the few areas where Java's polite simplicity
doesnt really shine, lol. It requires more code than beginners
are used to for what can be perceived as a trivial task.
There are lots of good sound tutorials online. Its just going to take
a lot of work on your part. Good luck.
> Sound is one of the few areas where Java's polite
> simplicity
> doesnt really shine, lol. It requires more code than
> beginners
> are used to for what can be perceived as a trivial
> task.
>
> There are lots of good sound tutorials online. Its
> just going to take
> a lot of work on your part. Good luck.
Yeah, I noticed, heh. I'm used to BASIC where it takes two lines to play a sound. "load sound "filename.wav", soundNum" and "play sound soundNum, startPosition", so it's a big transition having to type 100 lines of code to play a simple sound. Very annoying really, heh :P. I've looked at tutorials, but none have worked, and I have no idea what they are doing. They aren't even using methods, which is the only way I know to do things, and their coding habits are terrible and near impossible to read. I'm incredibly confused, why can't they just make it simpler :S.
> GAH, I'm still getting that it can't find the
> classes. Would anyone be kind enough to make me a
> complete program that runs by itself that just plays
> a simple .wav file? I have no idea what I'm doing
> with this.
I want you to feel welcome here but I almost feel a bit compelled to
voice my frustration with that post, lol.
I googled "java play wav" and the FIRST result was a usable example:
http://www.anyexample.com/programming/java/java_play_wav_sound_file.xml
You really just need to keep at it. Its the only way to learn.
> GAH, I'm still getting that it can't find the
> classes. Would anyone be kind enough to make me a
> complete program that runs by itself that just plays
> a simple .wav file? I have no idea what I'm doing
> with this.
I want you to feel welcome here but I almost feel a bit compelled to
voice my frustration with that post, lol.
I googled "java play wav" and the FIRST result was a usable example:
http://www.anyexample.com/programming/java/java_play_wav_sound_file.xml
You really just need to keep at it. Its the only way to learn.