Play a Sound with QuickTime for Java #73
Chapter 10, Audio
The one thing that’s really different is that you can play many more file for-
mats than you can with just JavaSound. Or maybe you can’t. It all depends
on what operating system you’re running on. The JMF install offers an all-
Java version and “performance packs” for some operating systems, which
use native code. The latter offer not only better performance for the media
formats supported by the all-Java version, they also integrate with the native
media library on the host operating system to play other media files, ones
that couldn’t be opened with the all-Java version alone.
This might make you deceive yourself: if you develop a JMF application on
Windows and it works with your media, it won’t necessarily work on
another operating system, either because Sun never made a performance
pack for that system (Mac OS X), or because even with the performance
pack, the native libraries don’t support that format. If you go the JMF route,
you need to rigorously test cross-platform, or you may very well have an
application that really only works on one OS.
H A C K
Play a Sound with QuickTime for Java Hack #73
Using QuickTime, you can play even more kinds of sounds, but only on two
QuickTime for Java offers another way to significantly improve the media
capabilities of your application. Its list of supported formats is huge (see
http://www.apple.com/quicktime/products/qt/specifications.html for the current
list) and always growing as Apple continues to improve it. That’s a big
advantage over JMF, which was dropped into maintenance mode in 1999
and largely ignored since then.
The huge disadvantage with QuickTime for Java is that it works on Win-
dows and Mac only. That’s because QTJ, as it’s typically called, is really just
an object-oriented (OO) wrapper to call C functions in the native Quick-
Time library. That gives you native-speed performance, but it also means the
wrappers don’t do anything without an underlying native implementation.
QuickTime Beating Up on JavaSound
For the purposes of this hack, let’s say you only need to support Mac and
Windows, or that you need to open files from the iTunes Music Store (QTJ
can do it, which is apparently the only way to do it in Java), or for whatever
reason QTJ looks like the right solution. Example 10-5 shows a port of the
JavaSound audio player to a QTJ-based implementation.