There's also an option to limit the maximum volume. Go to Settings > Sounds & Haptics > Headphone Safety. There, you can ...
The third step was writing the algorithm to detect loud music and adjust the volume accordingly. The Arduino will measure the audio until a sound greater than the dead band value, set with one of ...