How do I add a soundtrack to a movie?
Added: 31 Jan 2009. Working example for Java
Adding a soundtrack for a movie is extremely easy. The FSSoundConstructor provides all the information you need to define the sound then generate the blocks that are played in each frame of the movie:
FSSoundConstructor sounder = new FSSoundConstructor(soundFile);
float framesPerSecond = 12.0f;
int samplesPerBlock = sounder.getSampleRate() / (int) framesPerSecond;
int numberOfBlocks = sounder.getSamplesPerChannel() / samplesPerBlock;
movie.add(sounder.streamHeader(samplesPerBlock));
for (int i=0; i<numberOfBlocks; i++) {
movie.add(sounder.streamBlock(i, samplesPerBlock));
movie.add(new FSShowFrame());
}
One technique to make it easier to create movies with soundtracks is that you can add the sound using the FSLayer class or even create a movie clip that plays the sound. This keeps the sound objects separate from the objects that are dsiplayed and so you avoid having to interleave the streaming sound objects with those displayed on each frame.