My solution is tested on Android 4.2.1 and 5.0.2. There are three apps I'm aware of which can do the job here.
It's a paid app but works well for the objective.
- Create a profile in it using
+→Application → select your app.
- Create a task in it, then an action using
+ → Audio → Media Volume.
- Set the Level to the sound level you want in your app. (Hint: if you're running a music in background you would notice changes in the sound if you move the slider, thereby helping you to choose the level efficiently).
That's it. Play some music in the background, open the app you selected in instructions, and you would notice instant reduction in sound. Close the app and the sound level would return to the setting that were in place before launching the app.
It has two versions. The freeware can do the job but I didn't test if it has limits on active rules for being free.
Under My Rules tap Add Rule.
Choose Application Status Trigger under Trigger.
Tap the lens icon under Application → select your app → tap Next.
Choose Set Volume for Single Stream Action under Action.
Move the slider to desired sound level → choose Music Stream → tap Next.
Choose Default or No if you want to see a toast when the rule gets triggered → tap the floppy icon in the title bar to save the rule.
Now launch the app that you selected in this part of instructions and the media volume would go down with the launch. Sadly, in contrast to Tasker, the volume doesn't revert back to previous settings.
To overcome that, you may create a new application based rule featuring your launcher app and tweak the sound level under Music Stream action as we did earlier.
This is also a freeware and is said to be user friendly yet powerful app. Unfortunately, I don't how to use this app other than performing a rudimentary task. Regardless, it has a block (action) under Tools named Audio Volume Set which you may use to get the job done.
As for instructions of using this app, the app will show you the basic usage on the first run. And I already told you where to look for.