[an error occurred while processing this directive]

Previous | Home | Next

Jul 30, 2008

JavaScript Control of Video in Acrobat 9

One of the great new features in Adobe Acrobat 9 is the ability to add Flash Video or H.264 encoded video to any PDF page. If you have Acrobat Pro Extended, it will automatically convert virtually any video format into Flash video for you when you import the video. You can also reference URLs to video that will stream from the web.

Video Playbar Image

Adobe Acrobat 9 automatically adds playback controls called a "skin", when you add a video to a PDF page similar to the one at the bottom of the the image above.

However, if you want to control playback via buttons, links or other navigational features of PDF, you can use JavaScript to control the video too and even set the skin style to "none". The reason we can do this is because the skin is actually a Flash (SWF) wrapper around the video. The Adobe supplied skins have built in ActionScript functions that can be accessed via Acrobat JavaScript. The list of those functions and a link to an example file is below. You don't actually need to have any experience with ActionScript to use the functions but a basic understanding of Acrobat JavaScript would be helpful.

Note: Because the skins are simply Flash files, you can further customize the skins and even create your own using Adobe Flash CS3. Read Modifying Skins to see how.


ActionScript Playback Control Functions:
multimedia_play
multimedia_pause
multimedia_rewind
multimedia_nextCuePoint
multimedia_prevCuePoint
multimedia_seek, time (measured in seconds)
multimedia_mute
multimedia_volume, num (0<= num <= 1)

Use:
You need to begin by creating an object that represents the specific Rich Media Annotation that contains the video. Use the new getAnnotsRichMedia method to do that. this.getAnnotsRichMedia( pageNum:Integer ) returns an array of AnnotRichMedia objects for a given page but you can get just the one you are interested in by also giving the method the index number of the annotation. So your code might look like this for a single video on the first page of the PDF.

var annot = this.getAnnotsRichMedia(0)[0];

Then you can simply use the callAS (Call ActionScript) method and pass in the name of the function you want the skin to perform. Of course, you might want to add a line of code that will activate that annotation before playing if it is not already activated. To begin playing a video, your code might look like this.

if (!annot.activated) annot.activated=true;
annot.callAS("multimedia_play");

To see the code in the example file, open the file in Acrobat and turn on the "Advanced Editing" toolbar then choose the "Select Object" tool (the big black arrow) and select one of the buttons below the video box. Review the JavaScript in the MouseUp action in the Actions tab.

PDF icon Sample with Play, Pause and Rewind buttons.

permalink.gif Comments (0) Bookmark and Share


Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)