Widgets for Adobe Acrobat : VideoPlayerX

Using the vpx_listener() function

VideoPlayerX build 10.2 and later will look for a document-level JavaScript function named "vpx_listener" and if found, will send event messages to this function. If it's not defined, it won't. The point behind this feature is that in many cases you will want to take some action within the JS API based on events happening in the video (looping, stopping, etc.) but you cannot use the multimedia_registerEventHandler() method until the annotation is activated. If for example you want to automatically deactivate a floating window annotation when playback completes, you can use the vpx_listener() function to watch out for that event, and take the appropriate action.

Of course if your PDF software doesn't support JavaScript, or it's disabled, nothing will work!

Events sent to the function

The vpx_listener() function should have four parameters (RMA,Page,Pos,Event) and no return value:

RMA	name of the Rich Media Annotation (string)
Page	PDF page on which the RMA is located (integer, zero-based)
Pos     the playback position in seconds (float)
Event   the name of the event - such as "playing", "complete", etc. (string)

Values of "Event" are:

  • buffering
  • complete
  • connectionError
  • disconnected
  • loading
  • paused
  • playing
  • resizing
  • rewinding
  • seeking
  • stopped

Examples

Suppose your annotation has a name of "RM2" and has been placed on page 4. You want to disable this annotation (closing the floating window if present) when the video completes playback, but not affect any others in the document. You would define a document-level function as follows:

function vpx_listener(r,pg,pos,e) {
  if (r=="RM2" && pg==3 && e=="complete") {
     this.getAnnotRichMedia(pg,r).activated = false;
  }
}

Suppose you want to report every status message to the console, and open a website if a remote video fails to load. You would define a document-level function as follows:

function vpx_listener(r,pg,pos,e) {
  console.println("vpx_listener: RMA="+r+", page="+pg+", event="+e+", position="+p);
  if (e=="connectionError") app.launchURL("http://www.helpfulwebsite.abc/brokenvideo", true);
}

Auto-advancing

Suppose you want to automatically advance to the next page in the PDF file when a video finishes playing (i.e. it reaches the end, not when the user pauses it with the on-screen controls). The annotation should also deactivate itself to free up memory. You would define a document-level function as follows:

function vpx_listener(r,pg,pos,e) {
  if (e=="complete")  {
    this.pageNum++;
    this.getAnnotRichMedia(pg,r).activated = false;
    }
}

Back to VideoPlayerX