Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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)?

share|improve this question

1 Answer 1

up vote 9 down vote accepted

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,
  addresource=sound_sample.mp3,
  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}
share|improve this answer
    
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

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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