"media: inaccessible or not found" error when attempting to control device volume via ADB



  • I'm trying to https://stackoverflow.com/questions/21055947/adb-command-to-set-volume .

    When for instance running

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

    ...this error is returned ( https://stackoverflow.com/questions/24652747/what-is-the-difference-between-audiomanagers-stream-types-at-low-level 😞

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

    Oneplus 5T, LineageOS 18.1 (Android 11)

    https://developer.android.com/reference/android/media/AudioManager.html



  • 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.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2