Opening and Closing the QuickTime Session
All QTJ applications are responsible for managing the QuickTime
“session.” The call to
QTSession.open( ) gives QuickTime an opportunity
to initialize itself, and it must be made before any other QTJ call,
or you’ll get an exception. Similarly, you must call
QTSession.close( ) when you’re
done with QuickTime to give it a chance to clean up.
In general, this means you might want to call
QTSession.open( ) as early as possible and
QTSession.close( ) as late as possible. The former
is easy enough to do: just put it in your
application’s entry point or even in a static
initializer so that it precedes main( ). On the
other hand, ensuring that you call QTSession.close( ) gracefully is trickier, because your user could quit your
application with a menu item you provide, a Ctrl-C, a Cmd-Q (on Mac),
or (heaven forbid) a kill -9
your-pid from the command line. Ideally,
you’d like to have a fighting chance of properly
closing QuickTime in as many cases as possible.
How do I do that?
One way to close QuickTime late is to put QTSession.close() in a Java shutdown hook, which will get called as
the JVM goes away. There are no guarantees, but it’s
better than nothing.
Note
You can also run this example with the provided ant run-ch01-qtversioncheck task.
You can use the class in Example 1-4 as a
general-purpose session handler for QTJ. It is
presented here so that none of the other examples in the book will
need to explicitly handle opening or closing the
QTSession ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access