Class AudioPlayerInputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable

    public class AudioPlayerInputStream
    extends java.io.InputStream
    Provides an audio player as an input stream. When nothing is playing, it returns silence instead of blocking.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int available()  
      void close()  
      static javax.sound.sampled.AudioInputStream createStream​(AudioPlayer player, AudioDataFormat format, long stuckTimeout, boolean provideSilence)
      Create an instance of AudioInputStream using an AudioPlayer as a source.
      int read()  
      int read​(byte[] buffer, int offset, int length)  
      • Methods inherited from class java.io.InputStream

        mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AudioPlayerInputStream

        public AudioPlayerInputStream​(AudioDataFormat format,
                                      AudioPlayer player,
                                      long timeout,
                                      boolean provideSilence)
        Parameters:
        format - Format of the frames expected from the player
        player - The player to read frames from
        timeout - Timeout till track stuck event is sent. Each time a new frame is required from the player, it asks for a frame with the specified timeout. In case that timeout is reached, the track stuck event is sent and if providing silence is enabled, silence is provided as the next frame.
        provideSilence - True if the stream should return silence instead of blocking in case nothing is playing or read times out.
    • Method Detail

      • read

        public int read()
                 throws java.io.IOException
        Specified by:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] buffer,
                        int offset,
                        int length)
                 throws java.io.IOException
        Overrides:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • available

        public int available()
                      throws java.io.IOException
        Overrides:
        available in class java.io.InputStream
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.InputStream
        Throws:
        java.io.IOException
      • createStream

        public static javax.sound.sampled.AudioInputStream createStream​(AudioPlayer player,
                                                                        AudioDataFormat format,
                                                                        long stuckTimeout,
                                                                        boolean provideSilence)
        Create an instance of AudioInputStream using an AudioPlayer as a source.
        Parameters:
        player - Format of the frames expected from the player
        format - The player to read frames from
        stuckTimeout - Timeout till track stuck event is sent and silence is returned on reading
        provideSilence - Returns true if the stream should provide silence if no track is being played or when getting track frames times out.
        Returns:
        An audio input stream usable with JDK sound system