Search code examples
androidadbandroid-mediaplayer

how to get media player state using adb command


Can you please let me know if there are any adb commands to get the state of MediaPlayer like, Play/Pause etc.

This is what i tried like below.

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

Solution

  • If you are just looking if Audio is Paused or Played.

    You can try using

    $ 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
    

    In both, it shows if state is PLAYSTATE_PAUSED, PLAYSTATE_PLAYING or PLAYSTATE_STOPPED.

    I even tried it on different device,

    $ 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
    

    Here it shows the state:1 or state:2,
    It basically the value for that.

    PLAYSTATE_PLAYING
    PLAYSTATE_PAUSED
    PLAYSTATE_STOPPED

    You could parse the output of the above to get these values.
    Hopefully this is what you looking for.