question

Nem avatar image
Nem asked

Alexa voice controls stop working after backgrounding/foregrounding

Hi! In my application, Amazon voice controls (play, pause, fast-forward, rewind, etc...) functions as intended whenever the player is initialized, we request audio focus and begin playback. Stopping the player releases the media session properly as well, but seeing an issue when backgrounding/foregrounding the app.

When the player is in the foreground and the app is backgrounded, I make sure to call setActive in onStop which is what the Android documentation says. To confirm this, adb shell dumpsys media_session shows the media session of the app is set to false. Similarly, when foregrounding the app after it's been backgrounded setActive is called in onStart to resume the media session. The activity resumes as it should when the app is foregrounded, but the voice controls no longer work.

BEFORE BACKGROUNDING (WORKING)

~ $ adb shell dumpsys media_session
MEDIA SESSION SERVICE (dumpsys media_session)

6 sessions listeners.
Global priority session is null
User Records:
Record for full_user=0
  Volume key long-press listener: null
  Volume key long-press listener package: 
  Media key listener: null
  Media key listener package: 
  Callback: android.media.session.ICallback$Stub$Proxy@d1f086d
  Last MediaButtonReceiver: null
  Restored MediaButtonReceiver: null
  Media button session is com.android.package/com.android.package (userId=0)
  Sessions Stack - have 1 sessions:
    com.android.package com.android.package/com.android.package (userId=0)
      ownerPid=4487, ownerUid=10202, userId=0
      package=com.android.package
      launchIntent=null
      mediaButtonReceiver=null
      active=true
      flags=3
      rating type=0
      controllers: 2
      state=PlaybackState {state=3, position=16036, buffered position=24000, speed=1.0, updated=90848451, actions=3408767, custom actions=[], active item id=-1, error=null}
      audioAttrs=AudioAttributes: usage=USAGE_MEDIA content=CONTENT_TYPE_UNKNOWN flags=0x0 tags= bundle=null
      volumeType=1, controlType=2, max=0, current=0
      metadata:size=1, description=null, null, null
      queueTitle=null, size=0

Audio playback (lastly played comes first)
  uid=10202 packages=com.android.package


AFTER FOREGROUNDING (NOT WORKING)

~ $ adb shell dumpsys media_session
MEDIA SESSION SERVICE (dumpsys media_session)

6 sessions listeners.
Global priority session is null
User Records:
Record for full_user=0
  Volume key long-press listener: null
  Volume key long-press listener package: 
  Media key listener: null
  Media key listener package: 
  Callback: android.media.session.ICallback$Stub$Proxy@d1f086d
  Last MediaButtonReceiver: null
  Restored MediaButtonReceiver: null
  Media button session is com.android.package/com.android.package (userId=0)
  Sessions Stack - have 1 sessions:
    com.android.package com.android.package/com.android.package (userId=0)
      ownerPid=5706, ownerUid=10202, userId=0
      package=com.android.package
      launchIntent=null
      mediaButtonReceiver=null
      active=true
      flags=3
      rating type=0
      controllers: 1
      state=PlaybackState {state=2, position=0, buffered position=2541, speed=0.0, updated=91045407, actions=3408767, custom actions=[], active item id=-1, error=null}
      audioAttrs=AudioAttributes: usage=USAGE_MEDIA content=CONTENT_TYPE_UNKNOWN flags=0x0 tags= bundle=null
      volumeType=1, controlType=2, max=0, current=0
      metadata:size=1, description=null, null, null
      queueTitle=null, size=0

Audio playback (lastly played comes first)
  uid=10202 packages=com.android.package


The only notable difference I see after foregrounding is that there is one less controller. That's probably the reason voice control stops working after backgrounding/foregrounding the app, but I'm not sure. This also doesn't happen on Android devices an happens on all Fire OS devices.

Any advice would be appreciated!

alexa voice servicealexa
1 comment
10 |5000

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

So for some reason the media session needs to be set to active ONLY when playback is occurring. Even if the player has audio focus, it's not enough.

0 Likes 0 ·

0 Answers