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( ...
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.