# Play animated graphic when “next slide” is clicked

I am giving a presentation and I have included an animatedgraphic in the following way:

\animategraphics[scale=0.4,autoplay]{8}{movie}{000}{200}


As you can see, this is played automatically. But I want to have it in the following way:

I use a presentation tool, where I can click on "next slide" and "previous slide". So this tool is just imitating the left cursor and right cursor you would normally use to click to the next / previous slide. How can I tell LaTex to play the animation, when I click on "next slide". Is this possible using a presenter?

EDIT:

Ignore the presenter, a solution for the right cursor is ok!

• I am still searching for an answer to this question, so any help would be appreciated! Thanks! – Jen Bohold Aug 7 '13 at 10:37
• Unfortunately this looks like more of a Javascript problem than TeX. So maybe only the author himself can answer. – percusse Aug 8 '13 at 8:27

Put

\alt<2>{%
\animategraphics[scale=0.4,autoplay]{8}{movie}{000}{200}%
}{%
\includegraphics[scale=0.4]{movie000}%
}


into the frame body.

Complete example using multipage PDF from pkg mwe as animation frames:

\documentclass{beamer}

\usepackage{animate}

\begin{document}

\begin{frame}[t]{Animation}
\dots started on next slide'':\\[2ex]

\alt<2>{%
\animategraphics[height=2in,autoplay]{8}{example-image-a4-numbered}{}{}%
}{%
\includegraphics[height=2in,page=1]{example-image-a4-numbered}%
}
\end{frame}

\end{document}


An easy way to avoid code duplication is described in this workaround:

• variable \myframe defines the number of frames composing the animation
• overlay command \only overwrites the value of \myframe depending on which (beamer) frame you are.

\documentclass{beamer}
\usepackage{default}
\usepackage{tikz}
\usepackage{animate}
\usepackage{xcolor}

\begin{document}
\begin{frame}{autoplay next slide example}
%% variable myframe decides how many frames the animation is composed of
\only<1>{\def\myframes{1}}
\only<2>{\def\myframes{81}}

\begin{animateinline}[poster=first,autoplay]{12}%
%%  variable rl defines the percentual variation in the position of the moving object
\multiframe{\myframes}{rl=0+.0125}{%

\begin{tikzpicture}
\clip (-.5,-.5) rectangle (10,7); %% visible rectangle
\draw[draw=black, fill=black] (1+3*\rl, 2+4*\rl) circle (3pt);
\end{tikzpicture}
}
\end{animateinline}
\end{frame}
\end{document}

• You could add \def\nomouse{nomouse}\def\autoplay{} to <1> and \def\nomouse{}\def\autoplay{autoplay} to <2>, and set animateinline options to [\autoplay,\nomouse]. Option poster is not really necessary as the first frame is shown by default. – AlexG Sep 28 '18 at 9:44
• Off-topic: You don't need \usepackage{xcolor} with beamer – user36296 Sep 28 '18 at 10:52

I was totally struggling to make this work, since i can't implement AlexG's solution to every single animation i want to use - this requires to split each animation into first frame and other frames, or have some other artificial slides before the animation could start.

For my purposes, of no controls

\begin{animateinline}[autoplay, loop, method=widget]

For me I did this

\animategraphics[loop,autoplay,width=\linewidth]{10}{figures/reaction/}{1}{20}

and it works perfectly

I implemented a first brute force solution, which is not a real technical solution to this problem, but somehow it is a solution for this problem:

I just copied the frame and changed the frame before to \includegraphics.

Then I added before the next frame which contains the animation a

\addtocounter{framenumber}{-1}


So when I now click on next slide the next slide appears and this has an autoplay.

(nothing else changes, the frame number is the same, so the audience should not notice it)