[Tex/LaTex] Playing portions of MP3 in PDF


I'm working on a book which should allow the playing of MP3s at selected points. I've found a good solution for the general case (i.e. the entire file): Audio examples in phonetics project, however, I also want to play portions of the files as well (e.g. words or phrases within sentences).

One solution is to use audio software to split the file into the necessary sections, but this of course produces a lot of unnecessary duplication.

The documentation for media9 mentions seek, which is half a solution (though I confess it isn't clear to me how to make this work). Hunting through JavaScript documentation has revealed this code, which suggests it is possible:

var player = app.media.openPlayer({
  rendition: this.media.getRendition( "myAudio" ),
  doc: this,
  settings: {
  startAt: 3,
  endAt: 8

The MWE given in the link above is as follows:


Sound sample: \includemedia[

I'd be grateful for any suggestions on how to proceed.

Best Answer

Version 2014/06/25 of media9 has updated players APlayer.swf and VPlayer.swf.

The play and pause methods of their programming interface now accept optional arguments which are time offsets, measured in seconds, into the media file. Thus, a properly configured \mediabutton lets the embedded player play a portion of the media file.

A generic sound example with two buttons which is similarly useable for video:

]{\fbox{Play entire file}}{APlayer.swf}

  mediacommand=mysound:play [(10.0)],
  mediacommand=mysound:pause [(33.0)]
]{\fbox{Play from 10 s until 33 s}}

  mediacommand=mysound:play [(41.0)],
  mediacommand=mysound:pause [(63.0)]
]{\fbox{Play from 41 s until 1:03 min}}

In the particular case of a phonetics project, the same sound file may need to be playable on different pages of the document. Here we need to embed the audio player at least once per sound file and per page on which the player is referenced by media buttons. For this to do automatically, the code example below defines the command

\playSoundFromTo{<mp3 file path or URL>}{<tStart>}{<tEnd>}{<button text>}

Note, that a particular sound file and the player SWF are only once embedded physically into the document. Thus, repeated \includemedia for the same sound file on different pages do not add much to the PDF file size.

Complete example using a sound URL: enter image description here


% #1 audio file/URL, #2 from (secs), #3 to (secs), #4 button text
  % get abs. page No. this button is on, using zlabel/zref
  % insert player only once for *this* audio file on *this* page
  \ifcsname #1.\btnpage\endcsname\else%
%        &hideBar=true %enable this to make player invisible
    \expandafter\xdef\csname #1.\btnpage\endcsname{}%
  \mediabutton[%play button

\section{OpenBSD 4.9 Release Song}

\noindent\playSoundFromTo{http://www.openbsd.org/songs/song49.mp3}{5.5}{37.0}{\fbox{A couple of questions}}

\noindent\playSoundFromTo{http://www.openbsd.org/songs/song49.mp3}{39.0}{49.0}{\fbox{The answer}}

\noindent\playSoundFromTo{http://www.openbsd.org/songs/song49.mp3}{206.5}{221.0}{\fbox{Last harmonica solo}}