Run automation when media player plays next track?

Would it be possible to launch an automation every time a media player plays the next song? And if so, how?