O'Reilly logo

QuickTime for Java: A Developer's Notebook by Chris Adamson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.*; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required