Commit 693e1288 authored by Jean-Baptiste Kempf's avatar Jean-Baptiste Kempf

Reinstate compatibility with Android-7 !

Tested on Xperia X10, thanks to Nolvenn
parent f215d677
......@@ -92,6 +92,7 @@ public class AudioService extends Service {
private boolean mDetectHeadset = true;
private long mHeadsetDownTime = 0;
private long mHeadsetUpTime = 0;
private OnAudioFocusChangeListener audioFocusListener;
/**
* RemoteControlClient is for lock screen playback control.
......@@ -201,35 +202,36 @@ public class AudioService extends Service {
if(!Util.isGingerbreadOrLater()) // NOP if not supported
return;
audioFocusListener = new OnAudioFocusChangeListener() {
int volume = -1;
@Override
public void onAudioFocusChange(int focusChange) {
AudioManager am = (AudioManager)getSystemService(AUDIO_SERVICE);
if(focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK ||
focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT) {
volume = am.getStreamVolume(AudioManager.STREAM_MUSIC);
int maxVol = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
/*
* Lower the volume to 19% to "duck" when an alert or something
* needs to be played.
*/
am.setStreamVolume(AudioManager.STREAM_MUSIC, (int)(0.19*maxVol), 0);
} else {
if(volume != -1) {
am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0);
volume = -1;
}
}
}
};
AudioManager am = (AudioManager)getSystemService(AUDIO_SERVICE);
if(gain)
am.requestAudioFocus(audioFocusListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
else
am.abandonAudioFocus(audioFocusListener);
}
private final OnAudioFocusChangeListener audioFocusListener = new OnAudioFocusChangeListener() {
int volume = -1;
@Override
public void onAudioFocusChange(int focusChange) {
AudioManager am = (AudioManager)getSystemService(AUDIO_SERVICE);
if(focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK ||
focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT) {
volume = am.getStreamVolume(AudioManager.STREAM_MUSIC);
int maxVol = am.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
/*
* Lower the volume to 19% to "duck" when an alert or something
* needs to be played.
*/
am.setStreamVolume(AudioManager.STREAM_MUSIC, (int)(0.19*maxVol), 0);
} else {
if(volume != -1) {
am.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0);
volume = -1;
}
}
}
};
}
private final BroadcastReceiver serviceReceiver = new BroadcastReceiver() {
@Override
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment