java - Issue playing audio with Stackoverflow's javasound tag example -
Reading about today's tags, I tried to apply the simple code that we can see there (some With minor modifications, instead of using file
as the URL
):
file file = new file (System.getProperty ("User.dir") + "/sound.wav"); Clip clip = audio system.gateclip (); AudioInputStream ais = AudioSystem.getAudioInputStream (file); Clip.open (AIS); // Exception
but I'm getting java.lang.IllegalArgumentException: invalid format
when I try to open AudioInputStream
However, when I try it with the following code received from the Internet < /sound.wav "); AudioInputStream ais = AudioSystem.getAudioInputStream (file); Audio format format = ais.getFormat (); DataLine.Info Info = New DataLine.Info (clip class, format); Clip clip = (clip) audio system. Galline (information); Clip.open (AIS); Clip.start ();
It does work: sound.wav
is played correctly - though, I think it should be clunky for something Which should be as simple as our first example, given itself on the tag.
By reading, I have accepted that invalid agreement exception
is thrown when [...] the audio format of the stream is not fully specified or invalid < / Code> However, it appears to be a valid format.
What's wrong with our first example? Accepts a file
as a logic, and, when seen from another example, this valid audio file data is displayed, because it works, I am clearly missing something is? And, if so, should not it be mentioned on the tag?
After some research, I came to know that this system could do something with the properties GetLine () can specify the default for methods (getLine (), getClip (), getSourceDataLine () and getTargetDataLine ()). If you call in one of these ways, then Java follows ():
The system property is set to javax.sound.sampled.Clip
javax.sound The .sampled.clip = mixer class is called great.mixer and the clip is great.clip.clip
when you request a clip , Java checks the following:
- If the mixer is found great.mixer and clips in it is great clip. , return this clip
- If the mixer is found great.mixer , but the clip in it is great.Clip is not.
- If there is no clip in the mixer great.mixer or if it is not found, then
great.clip.Clap - If no mixer is included great.clip.Clap , return the first clip of the mixer found first
- If a mixer is not specified in a clip, then what does this mean is that if you have an invalid R. Invalid archive exception
Gument exceptions are, do not install a clip in any mixer.
DataLine.Info info = New DataLine.Info (clip class, format);
You are defining a new clip which means that your next call will return this object instead of giving you an error in a getLine () method.
Comments
Post a Comment