rancidfrog
April 8th, 2017, 03: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
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