当应用程序处于前台时如何使音量摇杆影响媒体音量?

How to make volume rocker affect media volume when app is in foreground?

我想让音量摇杆在应用程序处于前台时影响媒体音量。我该怎么做?

根据 volume controls documentation:

To ensure that volume controls adjust the correct stream, you should call setVolumeControlStream() passing in AudioManager.STREAM_MUSIC.

setVolumeControlStream(AudioManager.STREAM_MUSIC);