[Tex/LaTex] media9 playPause behaviour inconsistent for embedded mp4 and swf

media9

I'm trying to embed a video in my thesis using the media9 package and have found that the behaviour of the mediacommand playPause changes depending on whether the embedded file is a swf or mp4 format.

For an SWF file the video is only paused when the mouse-button is held down while for an MP4 file a single mouse-click pauses the video.

Does anyone know why the behaviour is different and what I need to do to get the mp4 behaviour for SWF files?

(I realise that the obvious answer is to convert my SWF file to MP4 however I have spent the better part of 6 hrs trying to do that. Although I can convert the file using ffmpeg, for some reason it doesn't display once embedded even though the example file included with media9 does.)

A MWE showing the difference in behaviour is as follows. Note that I'm using MiKTeX 2.9, pdfTeX and TeXnicCenter all (re)installed a couple of weeks ago.


\documentclass{article}
\usepackage{media9}
\usepackage[english]{babel}

\begin{document}

\includemedia[label=test,addresource=contours.swf,activate=pagevisible,
              width=9cm,height=10cm,flashvars={source=test.swf&autoPlay=true&loop=true}]
              {}{contours.swf}
\mediabutton[mediacommand=test:playPause]{\fbox{Play/Pause}}

\includemedia[label=random,addresource=random.mp4,activate=pagevisible,
              width=9cm,height=10cm,flashvars={source=random.mp4&autoPlay=true&loop=true}]
              {}{VPlayer.swf}
\mediabutton[mediacommand=random:playPause]{\fbox{Play/Pause}}

\end{document}

The above contours.swf file may be accessed at this link.

Any help will be greatly appreciated.

Best Answer

The playPause media command can only be executed by VPlayer.swf loaded in the RichMedia Annotation labelled random.

playPause is one of a small number of interface functions (API) implemented in VPlayer.swf (and APlayer.swf, by the way). You may have a look into the sources VPlayer.mxml and APlayer.mxml that ship with media9.

If you wanted to add API functions to contours.swf, you would have to program them in ActionScript, which is the programming language behind Flash, and compile them into contours.swf. Interface functions are added to a Flash application by means of the ExternalInterface.addCallback(...) ActionScript method.

The reason why your swf pauses while pressing the mouse button is that you simply keep AdobeReader busy by this action. You could press the button anywhere on the page with the same effect. You don't really call a dedicated function within your SWF.

BTW, the YouTube Player (see first example in the documentation media9.pdf) provides a completely different set of interface functions (documented here). playPause isn't implemented there either, but playVideo and pauseVideo are, amongst others. Thus, you would have to insert two \mediabuttons for pausing and resuming playback:

\includemedia[
  label=yt1,
  width=0.6\linewidth,height=0.45\linewidth,
  activate=pageopen,
  flashvars={
    enablejsapi=1    % enables yt player api used in media buttons
  }
]{}{https://www.youtube.com/v/Mdc3o7wOwNA?rel=0}   % online Flash file (YouTube Player)

\mediabutton[mediacommand=yt1:playVideo]{\fbox{\strut Play}}
\mediabutton[mediacommand=yt1:pauseVideo]{\fbox{\strut Pause}

PS: contours.swf doesn't need to be added as a resource, it is already the main Flash application executed by activating the RichMedia Annotation.

How did you create contours.swf? FFmpeg can't decode it.

Related Question