Rabbit-R1/android (non root)/java/sources/androidx/media3/exoplayer/AudioBecomingNoisyManager.java

63 lines
2.1 KiB
Java
Raw Normal View History

2024-05-21 16:08:36 -05:00
package androidx.media3.exoplayer;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;
/* loaded from: classes2.dex */
final class AudioBecomingNoisyManager {
private final Context context;
private final AudioBecomingNoisyReceiver receiver;
private boolean receiverRegistered;
/* loaded from: classes2.dex */
public interface EventListener {
void onAudioBecomingNoisy();
}
public AudioBecomingNoisyManager(Context context, Handler handler, EventListener eventListener) {
this.context = context.getApplicationContext();
this.receiver = new AudioBecomingNoisyReceiver(handler, eventListener);
}
public void setEnabled(boolean z) {
if (z && !this.receiverRegistered) {
this.context.registerReceiver(this.receiver, new IntentFilter("android.media.AUDIO_BECOMING_NOISY"));
this.receiverRegistered = true;
} else {
if (z || !this.receiverRegistered) {
return;
}
this.context.unregisterReceiver(this.receiver);
this.receiverRegistered = false;
}
}
/* loaded from: classes2.dex */
private final class AudioBecomingNoisyReceiver extends BroadcastReceiver implements Runnable {
private final Handler eventHandler;
private final EventListener listener;
public AudioBecomingNoisyReceiver(Handler handler, EventListener eventListener) {
this.eventHandler = handler;
this.listener = eventListener;
}
@Override // android.content.BroadcastReceiver
public void onReceive(Context context, Intent intent) {
if ("android.media.AUDIO_BECOMING_NOISY".equals(intent.getAction())) {
this.eventHandler.post(this);
}
}
@Override // java.lang.Runnable
public void run() {
if (AudioBecomingNoisyManager.this.receiverRegistered) {
this.listener.onAudioBecomingNoisy();
}
}
}
}