The SWF::Sound Module

The SWF::Sound object allows you to read in an MP3 file that can be played in the background of a movie. Add the sound to a particular frame of the movie with the SWF::Movie::setSoundStream( ) method, as in the following example:

my movie = new SWF::Movie;
my $sound = new SWF::Sound("goldenhair.mp3");   # A 30-second MP3
$movie->setRate(24);

# Make sure we have enough frames to accommodate the sound clip
# 30 seconds * 24 fps = 720 frames

$movie->setFrames(720);
$movie->setSoundStream($sound);

If the movie is shorter than the length of the sound clip, the sound is truncated, so we add enough frames to the movie to accommodate the entire 30 seconds.

Get Perl Graphics Programming 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.