If your headphones have a button and you press and hold this button, your Nexus 6 will activate voice search. I don't need voice search and I want to use this long-click for music control.
Edit the apq8084-taiko-tfs9890_stereo_co_Button_Jack.kl file, found under /system/usr/keylayout/:
Before: key 226 HEADSETHOOK
After: key 226 MEDIA_NEXT
Save the change and reboot.
Now use an app like the Headset Button Controller to configure the right (not left nor center) button to do what you want. Here is how I set the button:
Single click: Play/Pause
Double click: Next track
Triple click: Previous track
Quadruple click: Volume up (one step)
Long click: Volume down
Nice, now I have convenient and full control with just one button and I almost never need to touch my phone while playing music. Without this mod, I had to use quadruple alone for volume adjustment and every time I had to increase the vol from 0 by steps - quite a pain.
Note: even if your headphones have three buttons, most of them are Apple compatible and only the center one works on Android phones. After above mod, the center button appears as right button to the phone, which is why we configure the "right" button although we still use the center one (again, Android cannot see other buttons).
JAYS Headset Control
Ultimate HeadSet Controller
Headset Control Center