Skip to content

Commit 43d0543

Browse files
author
Robin
committed
close audio effect control session properly
1 parent 0787d62 commit 43d0543

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

app/src/main/java/org/schabi/newpipe/player/helper/AudioReactor.java

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import com.google.android.exoplayer2.SimpleExoPlayer;
1818
import com.google.android.exoplayer2.analytics.AnalyticsListener;
19+
import com.google.android.exoplayer2.decoder.DecoderCounters;
1920

2021
public class AudioReactor implements AudioManager.OnAudioFocusChangeListener, AnalyticsListener {
2122

@@ -50,6 +51,7 @@ public AudioReactor(@NonNull final Context context,
5051
public void dispose() {
5152
abandonAudioFocus();
5253
player.removeAnalyticsListener(this);
54+
notifyAudioSessionUpdate(false, player.getAudioSessionId());
5355
}
5456

5557
/*//////////////////////////////////////////////////////////////////////////
@@ -149,11 +151,21 @@ public void onAnimationEnd(final Animator animation) {
149151

150152
@Override
151153
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) {
152163
if (!PlayerHelper.isUsingDSP()) {
153164
return;
154165
}
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);
157169
intent.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, audioSessionId);
158170
intent.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, context.getPackageName());
159171
context.sendBroadcast(intent);

0 commit comments

Comments
 (0)