
Provide Audio Controls During Playback #78
Chapter 10, Audio
|
401
HACK
Of course, Sun could just go and actually implement getLevel( )…wouldn’t
that be nice?
H A C K
#78
Provide Audio Controls During Playback Hack #78
Let your users take control of JavaSound playback.
To complete this set of JavaSound-related hacks, why not give the user the
opportunity to control the sound as it plays? JavaSound provides a very
dynamic means of getting at controls like gain and pan (more commonly
thought of as volume and balance) through a discovery mechanism that you
can use to support any kind of control that might exist, even a control you
know nothing about.
On the other hand, JavaSound presents a control not as a GUI widget, but
just as an object that can affect the behavior of a
Line. This hack will help
you provide the GUI side.
The
Control class simply defines a getType( ) and toString( ) method.
What’s more interesting is its subclasses, each of which defines a different
kind of control:
BooleanControl
Controls a value that can be either true or false
EnumControl
Controls a value that can be one of n known values
FloatControl
Controls a value that is expressed as a floating-point number
CompoundControl
Controls multiple properties, and itself contains multiple controls
You can get the
Controls supported by your Line simply by calling Line.
getControls( )
, which returns an array of Controls. You can also ask for a
specific ...