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

Editing Tracks

Often, it makes sense to perform edits on all tracks of a movie. But for serious editing applications, sometimes you need to work at the track level, to add and remove tracks, or to work on just one track in isolation from the others. This task will provide a taste of that by adding a second audio track to a movie.

How do I do that?

The AddAudioTrackQTEditor builds on FlattenableQTEditor by adding another Add Audio Track... menu item, calling the doAddAudioTrack( ) method:

public void doAddAudioTrack( ) throws QTException { // ask for an audio file QTFile audioFile = QTFile.standardGetFilePreview (QTFile.kStandardQTFileTypes); OpenMovieFile omf = OpenMovieFile.asRead (audioFile); Movie audioMovie = Movie.fromFile (omf); // find the audio track, if any Track audioTrack = audioMovie.getIndTrackType (1, StdQTConstants.audioMediaCharacteristic, StdQTConstants.movieTrackCharacteristic); if (audioTrack = = null) { JOptionPane.showMessageDialog (this, "Didn't find audio track", "Error", JOptionPane.ERROR_MESSAGE); return; } // now make new audio track and insert segment // from the loaded track Track newTrack = movie.newTrack (0.0f, // width 0.0f, // height audioTrack.getVolume( )); // ick, need a dataref for our "new" media // http://developer.apple.com/qa/qtmtb/qtmtb58.html SoundMedia newMedia = new SoundMedia (newTrack, audioTrack.getMedia( ).getTimeScale( ), new DataRef (new QTHandle( ))); newTrack.getMedia( ).beginEdits( ); audioTrack.insertSegment (newTrack, 0, audioTrack.getDuration( ...

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