Moving Frame by Frame
One
popular feature for playback is the
ability to step forward exactly one frame. It turns out to be
trickier than one might initially expect: it’s not
like there’s a Movie.nextFrame( )
method. Indeed, a Movie
might not have a video
track at all, if it represents an MP3 or some other audio-only media.
So, finding the next frame requires being a little smarter about
looking inside the Movie
’s
structure.
How do I do that?
This example builds on the earlier BasicQTButtons
code. In this example, the implementations of the forward and back
buttons are altered so that instead of changing the play rate, they
change the current time to be the next frame before or after the
current time. For space, this example shows only the changes from the
original BasicQTButtons
.
This example needs to import quicktime.std
to use
StdQTConstants
, and
quicktime.std.clocks
for some time-related
classes. It also adds an instance variable
visualTrack
, which is found with the following
call:
theMovie = m; // find video track visualTrack = m.getIndTrackType (1, StdQTConstants.visualMediaCharacteristic, StdQTConstants.movieTrackCharacteristic);
If a visual track isn’t found, the
revButton
and fwdButton
are
disabled later in the constructor.
Finally, a new implementation of actionPerformed()
does the frame-step logic when the
revButton
or fwdButton
is
clicked:
if (e.getSource( ) = = revButton) { TimeInfo ti = visualTrack.getNextInterestingTime ( StdQTConstants.nextTimeMediaSample, theMovie.getTime( ...
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.