# How to play background music across multiple slides when making a beamer presentation?

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.

\documentclass{beamer}
\usepackage{media9}

\begin{document}

\begin{frame}{dumb frame}
\dots
\end{frame}

\begin{frame}{frame with sound \includemedia[
label=my_sound,
width=1ex, height=1ex, transparent,
activate=pageopen, deactivate=onclick,
flashvars={
source=sound_sample.mp3
&autoPlay=true
&hideBar=true
},
]{}{APlayer.swf}}
\dots
\end{frame}

\begin{frame}{other frame}
\dots
\end{frame}

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

\begin{frame}{another dumb frame}
\dots
\end{frame}

\end{document}

-
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