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

时间:2014-09-15 10:32:34

标签: 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

2 个答案:

答案 0 :(得分:3)

如果您只是在查看音频是暂停还是已播放。

您可以尝试使用

$ 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_PAUSEDPLAYSTATE_PLAYING还是PLAYSTATE_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
它基本上就是它的价值。

PLAYSTATE_PLAYING
PLAYSTATE_PAUSED
PLAYSTATE_STOPPED

您可以解析上述输出以获取这些值 希望这就是你要找的东西。

答案 1 :(得分:0)

另一种说法是来自AudioTrack::dump中的状态。

例如,在您的情况下:

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)

状态(2)告诉我们媒体暂停/停止。 state(0)表示媒体正在播放,state(1)表示播放媒体被某些弹出窗口中断。