Commit f326f711 by samrobinson Committed by Oliver Woodman

Added SendBroadcast as an Action.

Removed a redundant TestSimpleExoPlayer subclass.

PiperOrigin-RevId: 272681643
parent 3d5ab29d
......@@ -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;
......@@ -377,6 +379,16 @@ public final class ActionSchedule {
}
/**
* 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.
*
* @return The builder, for convenience.
......
......@@ -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());
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment