How do I toggle and animation?

This related topic is worth a check: Stop / Resume animation by code - #4 by Hermit