EasyMute, from developer familyLabs, is an app that can pause or mute your music by just waving your hand over your proximity sensor—whether the screen is on or off—all without needing root permissions.
Step 1: Install easyMute
You can grab easyMute for free directly from Google Play.
Step 2: Setting Up easyMute
There is an ongoing notification associated with easyMute to prevent it from closing, but you can disable that from your Settings app—Settings -> Apps -> easyMute and uncheck Show notifications. After disabling that, open easyMute and tap Settings.
Here, you can choose if you want the app to start on boot, as well as switch between pausing or muting your music on wave detection. There are also options to only allow the app to work only when your phone is on a flat surface or has headphones plugged in, both of which are great for saving some battery.
I chose to leave the Proximity Sensor Sensitivity and Sweep Threshold settings at their default values because they were set at a comfortable level, but feel free to mess with those on your own. Once you have all the settings to your liking, tap Enable easyMute and you will be ready to go!
Currently, easyMute has worked with every music player I've tried, including Google Play Music, HTC's Music app, Pandora, 8tracks, and MixRadio. However, if you do run into errors, be sure you are waving directly over the proximity sensor, which is right next to the front facing camera on both the M7 and M8.