Note: This solution is out of date, since Omxplayer is deprecated. I have open-sourced the code on GitHub and invite other devs to adapt it for newer Pi devices and software.