This question already has an answer here:
I want to prevent my laptop (running Ubuntu 12.04) from going to suspend mode(as wifi gets disconnected) while watching video(youtube, totem_player) and especially when downloading files from my Chrome browser. Also, is there a way to detect if the video is playing or not so that the computer may go to suspend mode only when video is not playing or paused. Further, I already tried Caffeine and it is continuously detecting open Video_Player even though nothing is playing (on pause or stop mode). Is there an efficient way of accomplishing this ?