Class AudioPlaybackPanel

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public final class AudioPlaybackPanel extends JPanel
A reactive panel that encapsulates audio playback functionality.

This panel is a high-salience observer of the autonomous Audio toolkit. It synchronizes the UI dropdown with the session's selected output device and provides the engine for notification sounds and tool-invoked playback.

See Also:
  • Field Details

    • agiPanel

      private final AgiPanel agiPanel
      The parent agi panel providing session context.
    • playbackLineComboBox

      private final org.jdesktop.swingx.JXComboBox playbackLineComboBox
      The dropdown for selecting the hardware playback line.
    • playbackLevelBar

      private final JProgressBar playbackLevelBar
      Real-time volume meter for playback feedback.
    • playing

      private final AtomicBoolean playing
      Flag indicating if audio is currently being played.
    • currentClip

      private volatile Clip currentClip
      Reference to a short notification clip currently in flight.
    • toolkitListener

      private EdtPropertyChangeListener toolkitListener
      Listener for toolkit-driven device selection changes.
  • Constructor Details

    • AudioPlaybackPanel

      public AudioPlaybackPanel(AgiPanel agiPanel)
      Constructs a new AudioPlaybackPanel and binds it to the Audio toolkit.
      Parameters:
      agiPanel - The parent AgiPanel.
  • Method Details

    • getAudioToolkit

      private Audio getAudioToolkit()
      Resolves the autonomous Audio toolkit from the session.
      Returns:
      The toolkit instance or null.
    • bindToToolkit

      private void bindToToolkit()
      Binds the UI listener to the toolkit's property change support.
    • playSound

      public void playSound(String resourceName)
      Plays a short, non-blocking notification sound from the application's resources.
      Parameters:
      resourceName - The name of the sound file (e.g., "idle.wav").
    • playToggleable

      public Runnable playToggleable(byte[] data, Consumer<Boolean> onStatusChange)
      Starts a toggleable audio playback from a byte array.
      Parameters:
      data - The PCM audio data.
      onStatusChange - Callback for play/stop events.
      Returns:
      A stopper Runnable that cancels the playback task.
    • stop

      public void stop()
      Stops all currently playing notification sounds and releases resources.

      This method terminates the execution of the currentClip and clears the reference to ensure proper garbage collection. It also resets the global playing state.

    • initPlaybackLineComboBox

      private void initPlaybackLineComboBox()
      Discovers available playback hardware and populates the UI dropdown.