This demo shows a few different UI components for playing audio:
AudioPlayerComponent
and the accompanying BasicAudioPlayerUI
WaveformSliderUI
for JSlidersAquaAudioListUI
for JListsThe BasicAudioPlayerUI
contains the WaveformSliderUI
by default, so to invoke both you just call:
AudioPlayerComponent apc = new AudioPlayerComponent(); apc.setSource(wavURL);
The AquaAudioListUI
can be set up via:
JList<URL> list = new JList<>(listModel); list.setUI(new AquaAudioListUI());
The com.pump.audio.AudioPlayer
does all the heavy lifting regarding actually playing/pausing any javax.sound.sampled.AudioInputStream
. Both of the UI components described below use this to help manage playback. This class includes an interface to notify listeners about the current playback progress/state. Currently I've only tested this against WAV files, but in theory any audio file you can convert to an AudioInputStream
should work.
The AudioPlayerComponent
is a very simple JComponent
that maintains a reference to a "source" (a URL) and an AudioPlayerUI
. The AudioPlayerUI
is an abstract class with a few helper methods, but currently the only subclass is the BasicAudioPlayerUI
. This is the UI you see in this demo: it includes a play/pause button that toggles, and a JSlider that uses the WaveformSliderUI
.
The WaveformSliderUI
is pretty self-explanatory. It extends BasicSliderUI
, but instead of a thumb and a line/track: it renders a hairline cursor and a waveform image.
This is a com.pump.plaf.decorate.DecoratedListUI
modeled after a similar UI observed on Mac. When an audio URL is selected you can play it back (or delete it).
I made all the sounds used in this demo, and they're available here under a Creative Commons Zero license.