Estimated, at least 50% of the questions starting with "is there a way (settings or app)..." can be answered straight away with the "big T" -- Tasker. That's an automation tool which doesn't come cheap (about 5 bucks; a free trial is available at its homepage), but is worth every cent. It works with so-called "profiles", where each profile consists of conditions and a task. So let me propose such a profile for you:
- Cell Near (set this up at work, let Tasker record all "cells near")1
- State → Headset plugged (check "invert" to make it the opposite)
1 this refers to your provider's mobile cell towers, and is the "cheapest" location mode in terms of battery (as the cells must either be scanned for calls/SMS/mobile data being available). If that's not exact enough, you may add GPS location or WiFi near (to scan for e.g. your office's WiFi AP) -- which then only kick in as soon as one of the listed cells is detected, again to save your battery.
2 Check whatever you want here. You could completely silence your phone (that would affect ringtone and phonecalls as well), but you probably just want the media volume set to zero.
So what happens with that profile? As soon as you come near to your workplace ("cell near", the mobile tower(s) close to the office), and the headset is not connected, media volume (assuming you chose that) will be silenced -- as the condition is completely met ("at office, headset not plugged"). Now you start your player and hear -- nothing. But once you plug the headset in, the condition is no longer valid -- and Tasker reverts to the settings as they've been before the profile was activated (so you can hear music via headphones).