FAQ Database Discussion Community


Playing multiple sound clips using Clip objects

java,swing,audio,javasound,clip
I am developing a program that has numerous JButton objects, and I want each one to correspond to its own .wav file. Also, I want the sounds to work in a way such that they can overlap with other buttons' sounds, but it cannot overlap with itself (clicking a button...

How to code to play MP3?

java,mp3,javasound
I was making a few lines of code which alternatively prints out "tick"s and "tock"s every 0.5 second, and prints out "done!" after 60 seconds. import javax.sound.sampled.*; public class Thread0001 { public static void main(String args[]) { for(int i=0; i<60; i++) { try { Thread.sleep(500); if(i%2 == 0) { System.out.print("tick...

Restarting a Clip object - flush() method

java,flush,javasound,clip,javax.sound.sampled
The Javadoc for DataLine.flush() states Flushes queued data from the line. The flushed data is discarded. In some cases, not all queued data can be discarded. For example, a mixer can flush data from the buffer for a specific input line, but any unplayed data already in the output buffer...

How to completely load audio but play it later?

java,audio,javasound
So, I have an AudioInputStream, which reads from a FileInputStream. I want to close the FileInputStream which will close the AudioInputStream. Is there any way to load the audio completely, so that I don't have to stream it directly from the file?...

Keeping audio clips in memory

java,swing,audio,memory,javasound
I am making a game and I have noticed that keeping all the audio files in memory is generally not really memory efficient as longer (and therefor larger) audio files take up quite a lot of memory. I was wondering at which size the game should decide to stream the...

Convert mp3 to WAVE in java without external libraries

java,audio,javasound
Is there a way to convert a mp3 audio file into a wav audio file in java without using external libraries?

How to wait till an audio clip is loaded?

java,audio,javasound
I'm quite a newbie in JAVA and I am trying to read a clip. Here is my code : import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.Clip; import javax.sound.sampled.DataLine; import javax.sound.sampled.LineEvent; import javax.sound.sampled.LineListener; public class TestClipBis { protected static AudioFormat audioFormat; public...