How can I place an MP3 file in the page of a PDF, so that it can play the audio on a Windows machine with Adobe Acrobat Reader?

  • (Untested, since I don't have Windows, and Acrobat Reader on Linux hasn't been updated in a while). Doesn't \externalfigure[file.mp3] works? – Aditya Nov 10 '14 at 7:51

The following example defines \embedaudio. It implements the same specification for embedded media as the media9 LaTeX package. Audio files in the MP3 format are played back within the player component APlayer.swf shipping with media9. MP3 files specified as URL are first downloaded before embedding. Adobe Reader on the Windows or OSX platforms is required for playback.

See the media9 manual, Table 4 and Table 5 for how to configure APlayer via FlashVars and for how to use the keyboard to control playback. FlashVars are passed as the first argument of \embedaudio.

A similar command for embedding video with ConTeXt is given here.

% \embedaudio{<flashvars>}{<audio file | URL (MP3)>}{link text}
% flashvars documented in `texdoc media9`,  page 20
\protected\def\pdfobj{\pdfextension obj }
\def\pdflastobj{\numexpr\pdffeedback lastobj\relax}
\protected\def\pdfstartlink{\pdfextension startlink }
\protected\def\pdfendlink{\pdfextension endlink\relax}
    \immediate\pdfobj stream file {APlayer.swf}%
      /Type/Filespec/F (APlayer.swf)/UF (APlayer.swf)
      /EF <</F \the\pdflastobj\space 0 R>>
  \immediate\pdfobj stream file {#2}%
    /Type/Filespec/F (#2)/UF (#2)
    /EF <</F \the\pdflastobj\space 0 R>>
  \edef\audio{(#2) \the\pdflastobj\space 0 R}%
    /Asset \aplayer\space 0 R
    /Params <</Binding/Foreground/FlashVars (autoPlay=true&source=#2&#1)>>
    /Instances [\the\pdflastobj\space 0 R]
    /Assets <<
      /Names [(APlayer.swf) \aplayer\space 0 R \audio]
    /Configurations [\the\pdflastobj\space 0 R]
  \setbox0=\hbox{ }\immediate\pdfxform 0%
  \pdfstartlink user{
    /BS <</W 0/S/S>>
    /Contents (audio file:#2)
    /NM (rma:#2)
    /AP <</N \the\pdflastxform\space 0 R>>
    /RichMediaSettings <<
      /Activation <<
        /Presentation <<
          /Transparent true
          /PassContextClick false
      /Deactivation <</Condition/PC>>
    /RichMediaContent \rmcontent\space 0 R

\ConTeXt{} embedded audio example: \embedaudio{}{click.mp3}{\strut $\rightarrow$Click and listen!}

\ConTeXt{} audio-URL example: \embedaudio{}{http://www.openbsd.org/songs/song49.mp3}{\strut $\rightarrow$Click and listen!}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.