PDA

View Full Version : Audio Focus advanced setting, (do not stop playback)



rancidfrog
April 8th, 2017, 02:31 PM
Having advanced setting where audio focus is not lost when media played from other app and/or system

Vanilla music, I believe, handles it : onAudioFocusChange, L2121 (https://github.com/vanilla-music/vanilla/blob/master/src/ch/blinkenlights/android/vanilla/PlaybackService.java) for some reason hash gets converted to star so can not add it to url

public void onAudioFocusChange(int type)
{
Log.d("VanillaMusic", "audio focus change: " + type);

// Rewrite permanent focus loss into can_duck
if (mIgnoreAudioFocusLoss) {
switch (type) {
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
case AudioManager.AUDIOFOCUS_LOSS:
type = AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK;
}
}

switch (type) {
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK:
case AudioManager.AUDIOFOCUS_LOSS_TRANSIENT:
synchronized (mStateLock) {
if((mState & FLAG_PLAYING) != 0) {
mTransientAudioLoss = true;

if(type == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
setFlag(FLAG_DUCKING);
} else {
mForceNotificationVisible = true;
unsetFlag(FLAG_PLAYING);
}
}
break;
}
case AudioManager.AUDIOFOCUS_LOSS:
mTransientAudioLoss = false;
mForceNotificationVisible = true;
unsetFlag(FLAG_PLAYING);
break;
case AudioManager.AUDIOFOCUS_GAIN:
if (mTransientAudioLoss) {
mTransientAudioLoss = false;
// Restore all flags possibly changed by AUDIOFOCUS_LOSS_TRANSIENT_*
unsetFlag(FLAG_DUCKING);
setFlag(FLAG_PLAYING);
}
break;
}
}


Toggle in advanced setting would be needed to enable or disable Audio Focus, with optional pause on call, resume after call:
I.E.
https://s15.postimg.org/omn4jrncb/Screenshot_20170322_121236.png

rancidfrog
May 3rd, 2017, 04:47 PM
https://s30.postimg.org/e44lh8ich/Screenshot_20170504-004251.png

rancidfrog
May 6th, 2017, 03:02 PM
Android update
In MainService.java requestAudioFocus would need to be adjusted with boolean flag setting probably a enable/disable switch in advanced settings regarding Permanent Audio focus:

void requestAudioFocus() {
// Setting needed for Permanent Focus in advanced settings
// int AUDIOFOCUS_GAIN
// Constant Value: 1 (0x00000001)
if( permanentFocus)
if (this.mAudioManager != null && !this.mHaveAudioFocus && this.mAudioManager.requestAudioFocus(this, AUDIOFOCUS_GAIN, 1) == 1) {
this.mHaveAudioFocus = true;
registerRemoteControlClient();
}
else
if (this.mAudioManager != null && !this.mHaveAudioFocus && this.mAudioManager.requestAudioFocus(this, 3, 1) == 1) {
this.mHaveAudioFocus = true;
registerRemoteControlClient();
}

rancidfrog
June 30th, 2017, 02:59 AM
Can Always on playback no interruptions be considered?

Tweek
February 16th, 2018, 12:53 PM
Can Always on playback no interruptions be considered?

If you mean "do not interrupt playback when a notification comes in" that would be great. PowerAmp does that perfectly, now with Foobar I have to put my phone on silent all the time with playback over bluetooth.