Storing a variable with app that has current audio focus?

Post your questions and help other users.

Moderator: Martin

Post Reply
Ghlave
Posts: 28
Joined: 06 Aug 2013 18:06

Storing a variable with app that has current audio focus?

Post by Ghlave » 06 Aug 2013 18:13

Is there some way to find out what app currently has audio focus and store it? I'm trying to set up my Nexus to resume playing when it gets a power source, but since Spotify, Google Play, Doggcatcher, all respond a bit differently to media keys, I need to know which one was previously playing.

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Storing a variable with app that has current audio focus

Post by Martin » 06 Aug 2013 19:16

Hi,

I'm not aware of an official API to get the current audio focus owner.
On a rooted device you can use Execute Root Command: dumpsys audio and use a script and string operations to find the last entry of the audio focus stack:

Sample Output (Android 4.3):

Code: Select all

Audio Focus stack entries (last is top of stack):
  source:android.os.BinderProxy@42b1f4e8 -- pack: com.google.android.music -- client: android.media.AudioManager@42463488com.google.android.music.playback.LocalDevicePlayback$8@42451970 -- duration: 1 -- uid: 10036 -- stream: 3
  source:android.os.BinderProxy@429beae0 -- pack: com.jetappfactory.jetaudio -- client: android.media.AudioManager@42668f88o.Κ@4272b630 -- duration: 1 -- uid: 10061 -- stream: 3
...
Regards,
Martin

Post Reply