Class PipedAudioStream

All Implemented Interfaces:
Closeable, AutoCloseable

@NonNullByDefault public class PipedAudioStream extends AudioStream
This is an implementation of an AudioStream used to transmit raw audio data to a sink. It just pipes the audio through it, the default pipe size is equal to 0.5 seconds of audio, the implementation locks if you set a pipe size lower to the byte length used to write. In order to support audio multiplex out of the box you should create a PipedAudioStream.Group instance which can be used to create the PipedAudioStream connected to it and then write to all of them though the group.
Author:
Miguel Álvarez Díez - Initial contribution
  • Constructor Details

  • Method Details

    • getFormat

      public AudioFormat getFormat()
      Description copied from class: AudioStream
      Gets the supported audio format
      Specified by:
      getFormat in class AudioStream
      Returns:
      The supported audio format
    • read

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

      public int read(byte @Nullable [] b) throws IOException
      Overrides:
      read in class InputStream
      Throws:
      IOException
    • read

      public int read(byte @Nullable [] b, int off, int len) throws IOException
      Overrides:
      read in class InputStream
      Throws:
      IOException
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class InputStream
      Throws:
      IOException
    • onClose

      public void onClose(Runnable onClose)
      Add a new handler that will be executed on stream close. It will be chained to the previous handler if any, and executed in order.
      Parameters:
      onClose - block to run on stream close
    • getOutputStream

      protected PipedOutputStream getOutputStream()
    • newGroup

      public static PipedAudioStream.Group newGroup(AudioFormat format)
      Creates a new piped stream group used to open new streams and write data to them. Internal pipe size is 0.5s.
      Parameters:
      format - the audio format of the group audio streams
      Returns:
      a group instance
    • newGroup

      public static PipedAudioStream.Group newGroup(AudioFormat format, int pipeSize)
      Creates a new piped stream group used to open new streams and write data to them.
      Parameters:
      format - the audio format of the group audio streams
      pipeSize - the pipe size of the created streams
      Returns:
      a piped stream group instance