|
16 | 16 |
|
17 | 17 | import com.google.android.exoplayer2.SimpleExoPlayer; |
18 | 18 | import com.google.android.exoplayer2.analytics.AnalyticsListener; |
| 19 | +import com.google.android.exoplayer2.decoder.DecoderCounters; |
19 | 20 |
|
20 | 21 | public class AudioReactor implements AudioManager.OnAudioFocusChangeListener, AnalyticsListener { |
21 | 22 |
|
@@ -50,6 +51,7 @@ public AudioReactor(@NonNull final Context context, |
50 | 51 | public void dispose() { |
51 | 52 | abandonAudioFocus(); |
52 | 53 | player.removeAnalyticsListener(this); |
| 54 | + notifyAudioSessionUpdate(false, player.getAudioSessionId()); |
53 | 55 | } |
54 | 56 |
|
55 | 57 | /*////////////////////////////////////////////////////////////////////////// |
@@ -149,11 +151,21 @@ public void onAnimationEnd(final Animator animation) { |
149 | 151 |
|
150 | 152 | @Override |
151 | 153 | public void onAudioSessionId(final EventTime eventTime, final int audioSessionId) { |
| 154 | + notifyAudioSessionUpdate(true, audioSessionId); |
| 155 | + } |
| 156 | + |
| 157 | + @Override |
| 158 | + public void onAudioDisabled(final EventTime eventTime, final DecoderCounters counters) { |
| 159 | + notifyAudioSessionUpdate(false, player.getAudioSessionId()); |
| 160 | + } |
| 161 | + |
| 162 | + private void notifyAudioSessionUpdate(final boolean active, final int audioSessionId) { |
152 | 163 | if (!PlayerHelper.isUsingDSP()) { |
153 | 164 | return; |
154 | 165 | } |
155 | | - |
156 | | - final Intent intent = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION); |
| 166 | + final Intent intent = new Intent(active |
| 167 | + ? AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION |
| 168 | + : AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION); |
157 | 169 | intent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, audioSessionId); |
158 | 170 | intent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, context.getPackageName()); |
159 | 171 | context.sendBroadcast(intent); |
|
0 commit comments