6

I'm trying to change volume on my device via ADB.

When for instance running

adb shell media volume --stream 15 --set 0

...this error is returned (regarding the volume streams):

/system/bin/sh: media: inaccessible or not found

Oneplus 5T, LineageOS 18.1 (Android 11)

Android documentation

1 Answer 1

7

In Android 11 and Android 12, media utility no longer exists. That's why you got the error since your shell could not find the utility in locations mentioned in its PATH. That utility's commands have been moved to a service name MediaSessionService. To access those commands invoke this service using cmd command.

adb shell cmd media_session

Example:

$ cmd media_session                                                                                                                           
usage: media_session [subcommand] [options]
       media_session dispatch KEY
       media_session dispatch KEY
       media_session list-sessions
       media_session monitor 
       media_session volume [options]

media_session dispatch: dispatch a media key to the system.
                KEY may be: play, pause, play-pause, mute, headsethook,
                stop, next, previous, rewind, record, fast-forword.
media_session list-sessions: print a list of the current sessions.
media_session monitor: monitor updates to the specified session.
                       Use the tag from list-sessions.
media_session volume:  the options are as follows: 
                --stream STREAM selects the stream to control, see AudioManager.STREAM_*
                                controls AudioManager.STREAM_MUSIC if no stream is specified
                --set INDEX     sets the volume index value
                --adj DIRECTION adjusts the volume, use raise|same|lower for the direction
                --get           outputs the current volume
                --show          shows the UI during the volume change
        examples:
                adb shell media volume --show --stream 3 --set 11
                adb shell media volume --stream 0 --adj lower
                adb shell media volume --stream 3 --get

The examples section above has not been updated in the source code to reflect new changes, that's why it still recommends using media or adb shell media.

2
  • I still get the error when running media_session list-sessions: /system/bin/sh: media_session: inaccessible or not found. cmd media_session outputs the same info as in your answer body. Hopefully I didn't make any obvious mistake, I'll look more into this tomorrow
    – user598527
    May 14 at 10:33
  • 1
    You have to use cmd before media_session. cmd utility is used to call shell commands offered by system services.
    – Firelord
    May 14 at 10:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .