android - 如何使用 adb 命令获取媒体播放器状态

标签 android adb android-mediaplayer

您能否告诉我是否有任何 adb 命令可以获取 MediaPlayer 的状态,例如播放/暂停等。

这是我尝试过的,如下所示。

c:\>adb shell dumpsys media.player
 Client
  pid(3764), connId(94), status(0), looping(false)
 AwesomePlayer
  fd(40), flags(0x00000010), bitrate(48000 bps)
  Track 1
   MIME(audio/mpeg), decoder(OMX.google.mp3.decoder)
 AudioOutput
  stream type(3), left - right volume(1.000000, 1.000000)
  msec per frame(0.000000), latency (-1)
  aux effect id(0), send level (0.000000)

 Client
  pid(3764), connId(93), status(0), looping(false)
 AwesomePlayer
  fd(35), flags(0x00084014), bitrate(48000 bps)
  Track 1
   MIME(audio/mpeg), decoder(OMX.google.mp3.decoder)
 AudioOutput
  stream type(3), left - right volume(1.000000, 1.000000)
  msec per frame(0.022676), latency (261)
  aux effect id(0), send level (0.000000)
 AudioTrack::dump
  stream type(3), left - right volume(1.000000, 1.000000)
  format(1), channel count(2), frame count(7680)
  sample rate(44100), status(0)
  state(2), latency (261)

 No media recorder client

 Files opened and/or mapped:
  /proc/749/fd/35 -> /storage/sdcard1/Music/xxx/aaaa.mp3
  /proc/749/fd/40 -> /storage/sdcard1/Music/xxx/bbbb.mp3

最佳答案

如果您只是查看音频是否已暂停或播放。

您可以尝试使用

$ adb shell dumpsys audio

Remote Control stack entries (last is top of stack):
/*....
* Some Output Here... 
*/
pi: PendingIntent{42feb5a8: PendingIntentRecord{42b6b748 com.google.android.music broadcastIntent}} -- pack: com.google.android.music  -- ercvr: ComponentInfo{com.google.android.music/com.google.android.music.playback.MediaButtonIntentReceiver}  -- client: android.media.IRemoteControlClient$Stub$Proxy@42e544d8  -- uid: 10059  -- type: 0  state: PLAYSTATE_PAUSED, 208457ms, 1.0X

Remote Control Client stack entries (last is top of stack):
  uid: -1  -- id: 1  -- type: 0  -- state: PLAYSTATE_STOPPED, PLAYBACK_POSITION_INVALID,     1.0X  -- vol handling: 1  -- vol: 15  -- volMax: 15  -- volObs: null
  uid: -1  -- id: 8  -- type: 0  -- state: PLAYSTATE_STOPPED, PLAYBACK_POSITION_INVALID, 1.0X  -- vol handling: 1  -- vol: 15  -- volMax: 15  -- volObs: null
  uid: 10059  -- id: 9  -- type: 0  -- state: PLAYSTATE_PAUSED, 208457ms, 1.0X  -- vol handling: 1  -- vol: 15  -- volMax: 15  -- volObs: null

在两者中,它显示状态是否为 PLAYSTATE_PAUSED , PLAYSTATE_PLAYINGPLAYSTATE_STOPPED .

我什至在不同的设备上尝试过,

$ adb shell dumpsys audio

Remote Control stack entries:

pi: PendingIntent{41b84660: PendingIntentRecord{42239310 com.sonyericsson.music broadcastIntent}}  -- ercvr: ComponentInfo{com.sonyericsson.music/com.sonyericsson.music.proxyservice.MediaButtonReceiver}  -- client: android.media.IRemoteControlClient$Stub$Proxy@428b5528  -- uid: 10049  -- type: 0  state: 2

Remote Control Client stack entries:
  uid: -1  -- id: 1  -- type: 0  -- state: 1  -- vol handling: 1  -- vol: 15  -- volMax: 15  -- volObs: null
  uid: -1  -- id: 2  -- type: 0  -- state: 1  -- vol handling: 1  -- vol: 15  -- volMax: 15  -- volObs: null
  uid: 10049  -- id: 5  -- type: 0  -- state: 2  -- vol handling: 1  -- vol: 15  -- volMax: 15  -- volObs: null

这里显示 state:1state:2 ,
它基本上就是它的值(value)。

PLAYSTATE_PLAYING
PLAYSTATE_PAUSED
PLAYSTATE_STOPPED

您可以解析上面的输出来获取这些值。
希望这就是您所寻找的。

关于android - 如何使用 adb 命令获取媒体播放器状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25846015/

相关文章:

android - 如何将任何硬代码值与数据库返回值连接或绑定(bind)?

android - 究竟是什么导致 adb devices => "device offline"

android - adb连接错误:An existing connection was forcibly closed by the remote host

android - 在没有 GUI 的情况下运行 Android 模拟器( headless (headless) Android)

android - 动态指定第一个 Activity

java - Android - 替换运行 fragment

android - 如何使用 FFmpeg 在单个命令中修剪、裁剪和添加叠加层

android - android旋转后如何更新SeekBar?

android - MediaPlayerNative : info/warning (10973, 0) 是什么意思?如何解决?