The Unexpected Concert
The Apple ecosystem is designed to be highly interconnected. If you put on your AirPods or connect your Mac to a set of Bluetooth speakers, macOS assumes you are ready to listen to media. If you happen to press the Play/Pause button on your keyboard (F8), or simply click the play button on your headphones, macOS will frequently launch the Apple Music app automatically and begin blasting whatever song happens to be at the top of your library. If you use Spotify, watch YouTube, or simply wanted silence, this aggressive default behavior from the native Music app is deeply annoying.
Severing the Media Keys
To retain control over your audio and stop macOS from automatically launching and playing Apple Music when you press a media key or connect headphones, you must utilize a third-party workaround or terminal command, as Apple offers no native toggle.
Apple deliberately hardcodes the Play/Pause key to prioritize the Apple Music app. The most effective way to break this link is by using a free, lightweight open-source utility called noTunes. You can download it from GitHub. Once installed and running, noTunes sits silently in your menu bar. Its entire purpose is to intercept the command that tells Apple Music to launch. When noTunes is active, pressing the Play button on your keyboard or headphones will successfully play or pause your currently active media (like a YouTube video in Safari) without ever accidentally waking up the heavy Apple Music application.