基于 Android 13 ,
cmd media_session usage :
console:/ # cmd media_session
usage: media_session [subcommand] [options]
media_session dispatch KEY
media_session list-sessions
media_session monitor <tag>
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-forward.
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
255|console:/ #
我是在串口操作的,所以不需要加 adb shell 。
获取媒体音量
255|console:/ # cmd media_session volume --stream 3 --get
[V] will control stream=3 (STREAM_MUSIC)
[V] will get volume
[V] Connecting to AudioService
[V] volume is 25 in range [0..100]
媒体音量加1
console:/ # cmd media_session volume --stream 3 --adj raise
[V] will control stream=3 (STREAM_MUSIC)
[V] will adjust volume
[V] Connecting to AudioService
媒体音量减1
console:/ # cmd media_session volume --stream 3 --adj lower
[V] will control stream=3 (STREAM_MUSIC)
[V] will adjust volume
[V] Connecting to AudioService
设置媒体音量设为20,并显示音量条UI
console:/ # cmd media_session volume --show --stream 3 --set 20
[V] will control stream=3 (STREAM_MUSIC)
[V] will set volume to index=20
[V] Connecting to AudioService
播放视频时,暂停、继续播放。可能不是所有应用都支持,不同应用支持的命令不一样。
console:/ # cmd media_session dispatch play
console:/ # cmd media_session dispatch pause