Play the Same Video from Any Page

| No Comments

It seems like I get a new question about playing video in PDF files every day. Adding dynamic content to PDF files seems to be catching on. Here’s the question… paraphrased for clarity.

I’d like to put a video on page one that opens in a floating window and use a button to start it from anywhere in the document.

First a reminder of how video can be played using the Flash Player in Acrobat 9. There are two ways to play the video in Acrobat or Reader, on the page or in a floating window.

Video Playing on the page
Click to Zoom

The floating window has certain advantages when you need the video to be present regardless of what page you are on in the PDF file. When playing in a floating window, you can continue to navigate through the document; flip pages, zoom in and out while the video plays uninterrupted.

Video playing in a floating window
Click to Zoom

Now – back to the question at hand.

While you can navigate the PDF file with an active video playing in a floating window, Acrobat can only start a video playing when the video is on a page that is visible. This means that if you had placed your video on page one and you are viewing the PDF file in single page mode, you can’t start the video playing from page two… or any other page unless page one is also visible. This fact prohibits the behavior that my questioner wants.

On the surface, it seems that the only way to get around that problem would be to put a copy of the video on every page. Except… video files are big. It’s not a very practical solution.

Luckily, the PDF file format is very well designed and incredibly efficient. As it turns out, multiple video widgets, Rich Media Annotations to be precise, can share a common data stream.

This means that if you place a 2.5Mb video onto page one of a PDF file, you’ve increased the file size by 2.5Mb. If you then add that same video file to page two, you’ve increased the file size again by 2.5Mb. But, if you instead copied the widget from page one and pasted it onto page two, all you’ve done is added a new widget to page two that references the same video asset as the widget on page one, increasing the file size by just a few bytes.

If you had set the video up to play when clicked, you’re basically done but you could have some usability issues. A user could very easily have more than one video window playing at the same time if they mistakenly decided to click on a second video widget while the first one was still playing. Just a little bit of JavaScript can come in handy to solve this issue as well. The remainder of this article describes how I constructed the example at the end.

How to Set Up the Same Video to Play from Any Page

The goal of this exercise is to create a PDF file with an embedded video that plays in a floating window and be able to activate it from any page without storing the large video file multiple times within the PDF.

Start by creating a small png file that is just a bunch of transparent pixels. I use one that is 100px x 100px but the dimensions don’t really matter, you’re going to use this image as the "poster" for the inactive widget but you want it to be hidden so you make it transparent.

Here are the steps

  1. Insert the video on page one. Choose Tools > Multimedia, and select the Video tool
  2. In the "Playback Style" area, select "Play content in floating Window"
  3. In the "Poster Image" area, select "Create poster from file" and select the .png file that you created earlier.
  4. Size and position the object – I made mine small and tucked it in the upper left corner of the page.
  5. Select the video widget using the "Select Object Tool" and copy the object.
  6. Paste the object onto the remaining pages of the document and position it where you want it.
  7. Go back to page one and create a button.
  8. In the mouse-up action of the button add the following JavaScript
    try { RMA.activated = false;  } catch (e){}
    RMA = this.getAnnotsRichMedia(this.pageNum)[0]
    RMA.activated = true;
  9. Copy the button to the remaining pages of the document

The JavaScript is the key. It makes sure that if a video from another page is running, that it is stopped and then it starts the video that is associated with the current page.

In the example below, the video file is about a 2.4Mb .FLV file. The PDF file with the video embedded is about 2.55Mb so even though you can start the video from either page one or two, you can tell from the size that the video is only stored once in the PDF file.

Play the Same Video from Any Page

Sorry, the comment form is closed at this time.

Sorry, the comment form is closed at this time.