Search code examples
javaaudiojavasound

How to completely load audio but play it later?


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?


Solution

  • You can store it in a Java Clip.

    Example:

    Clip clip = AudioSystem.getClip();
    clip.open(/*your AudioInputStream*/);
    

    Make clip a field, to use it later.