Songs within Applications
Will someone please give me the basic code needed to play a song within an application. Instead of giving me a link to a website could you actually paste the necessary code into the forum please. I also have a question on what types of audio files can be played. I have been trying to play a .wma file. Is that compatible? Please help.
[342 byte] By [
Ajd123a] at [2007-10-3 5:14:42]

it seems so... I've been trying to find a simple way to play a sound for quite some time, and the only thing that seemed ok was a trick with using some undocumented features (sun.audio.* package)...
here it is, but mind you, it's not something that should be normally used:
import sun.audio.*;//import the sun.audio package
import java.io.*;
//** 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);
To use a URL as the audio stream source, substitute the following for the input stream and audio stream setup:
AudioStream as = new AudioStream (url.openStream());
Playing the audio stream continuously adds a bit more complexity:
// Create audio stream as discussed previously.
// Create AudioData source.
AudioData data = as.getData();
// Create ContinuousAudioDataStream.
ContinuousAudioDataStream cas = new ContinuousAudioDataStream (data);
// Play audio.
AudioPlayer.player.play (cas);
// Similarly, to stop the audio.
AudioPlayer.player.stop (cas);
And there you have it. Remember, this technique uses undocumented features; there are no guarantees that it will work with anything but the current Sun JDK.