mirror of
https://github.com/Pinball3D/Rabbit-R1.git
synced 2024-12-30 11:02:31 -06:00
162 lines
8 KiB
Java
162 lines
8 KiB
Java
|
package androidx.media3.exoplayer;
|
||
|
|
||
|
import android.content.Context;
|
||
|
import android.os.Handler;
|
||
|
import android.os.HandlerThread;
|
||
|
import android.os.Message;
|
||
|
import androidx.media3.common.MediaItem;
|
||
|
import androidx.media3.common.Timeline;
|
||
|
import androidx.media3.common.util.Assertions;
|
||
|
import androidx.media3.common.util.Clock;
|
||
|
import androidx.media3.common.util.HandlerWrapper;
|
||
|
import androidx.media3.exoplayer.analytics.PlayerId;
|
||
|
import androidx.media3.exoplayer.source.DefaultMediaSourceFactory;
|
||
|
import androidx.media3.exoplayer.source.MediaPeriod;
|
||
|
import androidx.media3.exoplayer.source.MediaSource;
|
||
|
import androidx.media3.exoplayer.source.TrackGroupArray;
|
||
|
import androidx.media3.exoplayer.upstream.Allocator;
|
||
|
import androidx.media3.exoplayer.upstream.DefaultAllocator;
|
||
|
import androidx.media3.extractor.DefaultExtractorsFactory;
|
||
|
import com.google.common.util.concurrent.ListenableFuture;
|
||
|
import com.google.common.util.concurrent.SettableFuture;
|
||
|
|
||
|
/* loaded from: classes2.dex */
|
||
|
public final class MetadataRetriever {
|
||
|
private MetadataRetriever() {
|
||
|
}
|
||
|
|
||
|
public static ListenableFuture<TrackGroupArray> retrieveMetadata(Context context, MediaItem mediaItem) {
|
||
|
return retrieveMetadata(context, mediaItem, Clock.DEFAULT);
|
||
|
}
|
||
|
|
||
|
public static ListenableFuture<TrackGroupArray> retrieveMetadata(MediaSource.Factory factory, MediaItem mediaItem) {
|
||
|
return retrieveMetadata(factory, mediaItem, Clock.DEFAULT);
|
||
|
}
|
||
|
|
||
|
static ListenableFuture<TrackGroupArray> retrieveMetadata(Context context, MediaItem mediaItem, Clock clock) {
|
||
|
return retrieveMetadata(new DefaultMediaSourceFactory(context, new DefaultExtractorsFactory().setMp4ExtractorFlags(6)), mediaItem, clock);
|
||
|
}
|
||
|
|
||
|
private static ListenableFuture<TrackGroupArray> retrieveMetadata(MediaSource.Factory factory, MediaItem mediaItem, Clock clock) {
|
||
|
return new MetadataRetrieverInternal(factory, clock).retrieveMetadata(mediaItem);
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: private */
|
||
|
/* loaded from: classes2.dex */
|
||
|
public static final class MetadataRetrieverInternal {
|
||
|
private static final int MESSAGE_CHECK_FOR_FAILURE = 1;
|
||
|
private static final int MESSAGE_CONTINUE_LOADING = 2;
|
||
|
private static final int MESSAGE_PREPARE_SOURCE = 0;
|
||
|
private static final int MESSAGE_RELEASE = 3;
|
||
|
private final MediaSource.Factory mediaSourceFactory;
|
||
|
private final HandlerWrapper mediaSourceHandler;
|
||
|
private final HandlerThread mediaSourceThread;
|
||
|
private final SettableFuture<TrackGroupArray> trackGroupsFuture;
|
||
|
|
||
|
public MetadataRetrieverInternal(MediaSource.Factory factory, Clock clock) {
|
||
|
this.mediaSourceFactory = factory;
|
||
|
HandlerThread handlerThread = new HandlerThread("ExoPlayer:MetadataRetriever");
|
||
|
this.mediaSourceThread = handlerThread;
|
||
|
handlerThread.start();
|
||
|
this.mediaSourceHandler = clock.createHandler(handlerThread.getLooper(), new MediaSourceHandlerCallback());
|
||
|
this.trackGroupsFuture = SettableFuture.create();
|
||
|
}
|
||
|
|
||
|
public ListenableFuture<TrackGroupArray> retrieveMetadata(MediaItem mediaItem) {
|
||
|
this.mediaSourceHandler.obtainMessage(0, mediaItem).sendToTarget();
|
||
|
return this.trackGroupsFuture;
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: private */
|
||
|
/* loaded from: classes2.dex */
|
||
|
public final class MediaSourceHandlerCallback implements Handler.Callback {
|
||
|
private static final int ERROR_POLL_INTERVAL_MS = 100;
|
||
|
private MediaPeriod mediaPeriod;
|
||
|
private MediaSource mediaSource;
|
||
|
private final MediaSourceCaller mediaSourceCaller = new MediaSourceCaller();
|
||
|
|
||
|
public MediaSourceHandlerCallback() {
|
||
|
}
|
||
|
|
||
|
@Override // android.os.Handler.Callback
|
||
|
public boolean handleMessage(Message message) {
|
||
|
int i = message.what;
|
||
|
if (i == 0) {
|
||
|
MediaSource createMediaSource = MetadataRetrieverInternal.this.mediaSourceFactory.createMediaSource((MediaItem) message.obj);
|
||
|
this.mediaSource = createMediaSource;
|
||
|
createMediaSource.prepareSource(this.mediaSourceCaller, null, PlayerId.UNSET);
|
||
|
MetadataRetrieverInternal.this.mediaSourceHandler.sendEmptyMessage(1);
|
||
|
return true;
|
||
|
}
|
||
|
if (i == 1) {
|
||
|
try {
|
||
|
MediaPeriod mediaPeriod = this.mediaPeriod;
|
||
|
if (mediaPeriod == null) {
|
||
|
((MediaSource) Assertions.checkNotNull(this.mediaSource)).maybeThrowSourceInfoRefreshError();
|
||
|
} else {
|
||
|
mediaPeriod.maybeThrowPrepareError();
|
||
|
}
|
||
|
MetadataRetrieverInternal.this.mediaSourceHandler.sendEmptyMessageDelayed(1, 100);
|
||
|
} catch (Exception e) {
|
||
|
MetadataRetrieverInternal.this.trackGroupsFuture.setException(e);
|
||
|
MetadataRetrieverInternal.this.mediaSourceHandler.obtainMessage(3).sendToTarget();
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
if (i == 2) {
|
||
|
((MediaPeriod) Assertions.checkNotNull(this.mediaPeriod)).continueLoading(0L);
|
||
|
return true;
|
||
|
}
|
||
|
if (i != 3) {
|
||
|
return false;
|
||
|
}
|
||
|
if (this.mediaPeriod != null) {
|
||
|
((MediaSource) Assertions.checkNotNull(this.mediaSource)).releasePeriod(this.mediaPeriod);
|
||
|
}
|
||
|
((MediaSource) Assertions.checkNotNull(this.mediaSource)).releaseSource(this.mediaSourceCaller);
|
||
|
MetadataRetrieverInternal.this.mediaSourceHandler.removeCallbacksAndMessages(null);
|
||
|
MetadataRetrieverInternal.this.mediaSourceThread.quit();
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
/* JADX INFO: Access modifiers changed from: private */
|
||
|
/* loaded from: classes2.dex */
|
||
|
public final class MediaSourceCaller implements MediaSource.MediaSourceCaller {
|
||
|
private boolean mediaPeriodCreated;
|
||
|
private final MediaPeriodCallback mediaPeriodCallback = new MediaPeriodCallback();
|
||
|
private final Allocator allocator = new DefaultAllocator(true, 65536);
|
||
|
|
||
|
public MediaSourceCaller() {
|
||
|
}
|
||
|
|
||
|
@Override // androidx.media3.exoplayer.source.MediaSource.MediaSourceCaller
|
||
|
public void onSourceInfoRefreshed(MediaSource mediaSource, Timeline timeline) {
|
||
|
if (this.mediaPeriodCreated) {
|
||
|
return;
|
||
|
}
|
||
|
this.mediaPeriodCreated = true;
|
||
|
MediaSourceHandlerCallback.this.mediaPeriod = mediaSource.createPeriod(new MediaSource.MediaPeriodId(timeline.getUidOfPeriod(0)), this.allocator, 0L);
|
||
|
MediaSourceHandlerCallback.this.mediaPeriod.prepare(this.mediaPeriodCallback, 0L);
|
||
|
}
|
||
|
|
||
|
/* loaded from: classes2.dex */
|
||
|
private final class MediaPeriodCallback implements MediaPeriod.Callback {
|
||
|
private MediaPeriodCallback() {
|
||
|
}
|
||
|
|
||
|
@Override // androidx.media3.exoplayer.source.MediaPeriod.Callback
|
||
|
public void onPrepared(MediaPeriod mediaPeriod) {
|
||
|
MetadataRetrieverInternal.this.trackGroupsFuture.set(mediaPeriod.getTrackGroups());
|
||
|
MetadataRetrieverInternal.this.mediaSourceHandler.obtainMessage(3).sendToTarget();
|
||
|
}
|
||
|
|
||
|
@Override // androidx.media3.exoplayer.source.SequenceableLoader.Callback
|
||
|
public void onContinueLoadingRequested(MediaPeriod mediaPeriod) {
|
||
|
MetadataRetrieverInternal.this.mediaSourceHandler.obtainMessage(2).sendToTarget();
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|