I made a LaTeX beamer presentation and I would like to add background music to some of the slides. I did manage to play something using the media9 package, but only on a single slide, i.e. the sound stops when going to the next slide. Is it possible to embed a soundfile, let's say an MP3, that starts playing at a specific slide x and stops at another slide y (using media9 or any other package)?


There is a deactivate option with media9 inclusion command \includemedia. Default setting of deactivate is pageclose to unload the media player upon page change. If set to onclick, the media keeps playing in the background.

To automatically start playing, the activate command option must be set to either pageopen or pagevisible and the autoPlay Flash variable of the player must be set to true. In the code below, the sound starts playing automatically when a particular slide is opened. The sound keeps playing after leaving the slide.

To auto-stop the sound on a particular slide, we need some JavaScript that is run upon /O (page open) event of that slide.

Since version 11 of Adobe Reader, the media inclusion must take up some space (width x height) on the PDF page, otherwise the media remains dumb. In order to make the sound annotation invisible we make it transparent and suppress the progress bar of the sound player and place the whole thing after the slide heading.



\begin{frame}{dumb frame}

\begin{frame}{frame with sound \includemedia[
  width=1ex, height=1ex, transparent,
  activate=pageopen, deactivate=onclick,

\begin{frame}{other frame}

\pdfpageattr{/AA <</O <</S/JavaScript/JS (annotRM['my_sound'].activated=false;)>> >>}
\begin{frame}{frame where sound stops}

\begin{frame}{another dumb frame}

  • First of all thanks for your answer! I tried your solution, but unfortunately it does not quite work on my system. The sound starts on the correct slide, but it does not stop at all. I am using Windows 7 Prof 64 bit, Adobe Acrobat Reader Version 11.0.1. and its JavaScript is enabled. – Meneldur Jan 20 '13 at 20:08
  • Another question: Is it possible to hide the minute/second counter on the first slide as well? – Meneldur Jan 20 '13 at 20:11
  • @Meneldur Sorry, hideBar is not available in the CTAN version. I have just uploaded v.20 which will be on CTAN and in TeXLive within one day or two. Regarding auto-stopping, there was a bug in the code example that is fixed now. – AlexG Jan 21 '13 at 8:54
  • I tried the revised version and it works perfect. :) Thanks a lot! – Meneldur Jan 23 '13 at 19:41

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.