Providing Basic Audio Controls

Most audio applications provide some basic audio controls to allow the user to customize the sound output to suit his environment. The MovieController provides a volume control, but you can do better than that: you can control balance, bass, and treble with simple method calls.

How do I do that?

The AudioMediaHandler class provides the methods setBalance( ) and setSoundBassAndTreble( ), so it’s just a matter of getting the handler object. The key is to remember that:

  • Movies have tracks.

  • Tracks have exactly one Media each.

  • Each Media has a MediaHandler.

Iterate over the movie’s tracks to get each track’s media and handler. To figure out whether a given track is audio, you can use a simple instanceof to see if the handler is an AudioMediaHandler.

setBalance( ) takes a float, which ranges from -1.0 (all the way to the left) to 1.0 (all the way to the right), with 0 representing equal balance.

setSoundBassAndTreble( ) is interesting because it’s officially undocumented. As it turns out, you pass in ints for bass and treble, where 0 is normal, -256 is minimum bass or treble, and 256 is maximum.

Note

Well, the native version is undocumented. For once, the Javadocs have the useful info.

Example 7-3 provides a simple GUI to exercise these methods.

Note

Run this example with ant run-ch07-basicaudiocontrolsplayer.

Example 7-3. Providing balance, bass, and treble controls

package com.oreilly.qtjnotebook.ch07; import quicktime.*; import quicktime.std.*; import quicktime.std.movies.*; ...

Get QuickTime for Java: A Developer's Notebook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.