Added SendBroadcast as an Action.
Removed a redundant TestSimpleExoPlayer subclass. PiperOrigin-RevId: 272681643
This commit is contained in:
parent
3d5ab29da7
commit
f326f7110f
@ -15,9 +15,11 @@
|
||||
*/
|
||||
package com.google.android.exoplayer2.testutil;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Handler;
|
||||
import android.view.Surface;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.test.core.app.ApplicationProvider;
|
||||
import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.ExoPlaybackException;
|
||||
import com.google.android.exoplayer2.ExoPlayer;
|
||||
@ -210,6 +212,26 @@ public abstract class Action {
|
||||
|
||||
}
|
||||
|
||||
/** Broadcasts an {@link Intent}. */
|
||||
public static final class SendBroadcast extends Action {
|
||||
private final Intent intent;
|
||||
|
||||
/**
|
||||
* @param tag A tag to use for logging.
|
||||
* @param intent The {@link Intent} to broadcast.
|
||||
*/
|
||||
public SendBroadcast(String tag, Intent intent) {
|
||||
super(tag, "SendBroadcast: " + intent.getAction());
|
||||
this.intent = intent;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doActionImpl(
|
||||
SimpleExoPlayer player, DefaultTrackSelector trackSelector, Surface surface) {
|
||||
ApplicationProvider.getApplicationContext().sendBroadcast(intent);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the {@link Parameters} of a {@link DefaultTrackSelector} to specify whether the
|
||||
* renderer at a given index should be disabled.
|
||||
|
@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.google.android.exoplayer2.testutil;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Looper;
|
||||
import android.view.Surface;
|
||||
import androidx.annotation.Nullable;
|
||||
@ -32,6 +33,7 @@ import com.google.android.exoplayer2.testutil.Action.ExecuteRunnable;
|
||||
import com.google.android.exoplayer2.testutil.Action.PlayUntilPosition;
|
||||
import com.google.android.exoplayer2.testutil.Action.PrepareSource;
|
||||
import com.google.android.exoplayer2.testutil.Action.Seek;
|
||||
import com.google.android.exoplayer2.testutil.Action.SendBroadcast;
|
||||
import com.google.android.exoplayer2.testutil.Action.SendMessages;
|
||||
import com.google.android.exoplayer2.testutil.Action.SetPlayWhenReady;
|
||||
import com.google.android.exoplayer2.testutil.Action.SetPlaybackParameters;
|
||||
@ -376,6 +378,16 @@ public final class ActionSchedule {
|
||||
return apply(new SendMessages(tag, target, windowIndex, positionMs, deleteAfterDelivery));
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules broadcasting an {@link Intent}.
|
||||
*
|
||||
* @param intent An intent to broadcast.
|
||||
* @return The builder, for convenience.
|
||||
*/
|
||||
public Builder sendBroadcast(Intent intent) {
|
||||
return apply(new SendBroadcast(tag, intent));
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules a delay until any timeline change.
|
||||
*
|
||||
|
@ -36,7 +36,6 @@ import com.google.android.exoplayer2.source.MediaSource;
|
||||
import com.google.android.exoplayer2.source.TrackGroupArray;
|
||||
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
|
||||
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
|
||||
import com.google.android.exoplayer2.trackselection.TrackSelector;
|
||||
import com.google.android.exoplayer2.upstream.BandwidthMeter;
|
||||
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
|
||||
import com.google.android.exoplayer2.util.Clock;
|
||||
@ -413,8 +412,14 @@ public final class ExoPlayerTestRunner implements Player.EventListener, ActionSc
|
||||
() -> {
|
||||
try {
|
||||
player =
|
||||
new TestSimpleExoPlayer(
|
||||
context, renderersFactory, trackSelector, loadControl, bandwidthMeter, clock);
|
||||
new SimpleExoPlayer.Builder(context, renderersFactory)
|
||||
.setTrackSelector(trackSelector)
|
||||
.setLoadControl(loadControl)
|
||||
.setBandwidthMeter(bandwidthMeter)
|
||||
.setAnalyticsCollector(new AnalyticsCollector(clock))
|
||||
.setClock(clock)
|
||||
.setLooper(Looper.myLooper())
|
||||
.build();
|
||||
player.addListener(ExoPlayerTestRunner.this);
|
||||
if (eventListener != null) {
|
||||
player.addListener(eventListener);
|
||||
@ -614,27 +619,4 @@ public final class ExoPlayerTestRunner implements Player.EventListener, ActionSc
|
||||
public void onActionScheduleFinished() {
|
||||
actionScheduleFinishedCountDownLatch.countDown();
|
||||
}
|
||||
|
||||
/** SimpleExoPlayer implementation using a custom Clock. */
|
||||
private static final class TestSimpleExoPlayer extends SimpleExoPlayer {
|
||||
|
||||
public TestSimpleExoPlayer(
|
||||
Context context,
|
||||
RenderersFactory renderersFactory,
|
||||
TrackSelector trackSelector,
|
||||
LoadControl loadControl,
|
||||
BandwidthMeter bandwidthMeter,
|
||||
Clock clock) {
|
||||
super(
|
||||
context,
|
||||
renderersFactory,
|
||||
trackSelector,
|
||||
loadControl,
|
||||
/* drmSessionManager= */ null,
|
||||
bandwidthMeter,
|
||||
new AnalyticsCollector(clock),
|
||||
clock,
|
||||
Looper.myLooper());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user