Commit 7350981e by tonihei Committed by Oliver Woodman

Use higher level interface for method parameters where possible.

This makes it easier to use the helper methods because the player doesn't
have to be assigned to a SimpleExoPlayer in all cases.

PiperOrigin-RevId: 307039126
parent ece8d223
...@@ -3595,7 +3595,7 @@ public final class ExoPlayerTest { ...@@ -3595,7 +3595,7 @@ public final class ExoPlayerTest {
} }
}; };
SimpleExoPlayer player = ExoPlayer player =
new TestExoPlayer.Builder(context) new TestExoPlayer.Builder(context)
.setRenderers(rendererWaitingForData) .setRenderers(rendererWaitingForData)
.setLoadControl(loadControlWithMaxBufferUs) .setLoadControl(loadControlWithMaxBufferUs)
......
...@@ -23,6 +23,7 @@ import android.os.Looper; ...@@ -23,6 +23,7 @@ import android.os.Looper;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.google.android.exoplayer2.DefaultLoadControl; import com.google.android.exoplayer2.DefaultLoadControl;
import com.google.android.exoplayer2.ExoPlaybackException; import com.google.android.exoplayer2.ExoPlaybackException;
import com.google.android.exoplayer2.ExoPlayer;
import com.google.android.exoplayer2.LoadControl; import com.google.android.exoplayer2.LoadControl;
import com.google.android.exoplayer2.Player; import com.google.android.exoplayer2.Player;
import com.google.android.exoplayer2.Renderer; import com.google.android.exoplayer2.Renderer;
...@@ -307,8 +308,7 @@ public class TestExoPlayer { ...@@ -307,8 +308,7 @@ public class TestExoPlayer {
* Run tasks of the main {@link Looper} until the {@code player}'s state reaches the {@code * Run tasks of the main {@link Looper} until the {@code player}'s state reaches the {@code
* expectedState}. * expectedState}.
*/ */
public static void runUntilPlaybackState( public static void runUntilPlaybackState(Player player, @Player.State int expectedState) {
SimpleExoPlayer player, @Player.State int expectedState) {
verifyMainTestThread(player); verifyMainTestThread(player);
if (player.getPlaybackState() == expectedState) { if (player.getPlaybackState() == expectedState) {
return; return;
...@@ -334,7 +334,7 @@ public class TestExoPlayer { ...@@ -334,7 +334,7 @@ public class TestExoPlayer {
* Player.EventListener#onPlaybackSpeedChanged} callback with that matches {@code * Player.EventListener#onPlaybackSpeedChanged} callback with that matches {@code
* expectedPlayWhenReady}. * expectedPlayWhenReady}.
*/ */
public static void runUntilPlayWhenReady(SimpleExoPlayer player, boolean expectedPlayWhenReady) { public static void runUntilPlayWhenReady(Player player, boolean expectedPlayWhenReady) {
verifyMainTestThread(player); verifyMainTestThread(player);
if (player.getPlayWhenReady() == expectedPlayWhenReady) { if (player.getPlayWhenReady() == expectedPlayWhenReady) {
return; return;
...@@ -359,13 +359,13 @@ public class TestExoPlayer { ...@@ -359,13 +359,13 @@ public class TestExoPlayer {
* Run tasks of the main {@link Looper} until the {@code player} calls the {@link * Run tasks of the main {@link Looper} until the {@code player} calls the {@link
* Player.EventListener#onTimelineChanged} callback. * Player.EventListener#onTimelineChanged} callback.
* *
* @param player The {@link SimpleExoPlayer}. * @param player The {@link Player}.
* @param expectedTimeline A specific {@link Timeline} to wait for, or null if any timeline is * @param expectedTimeline A specific {@link Timeline} to wait for, or null if any timeline is
* accepted. * accepted.
* @return The received {@link Timeline}. * @return The received {@link Timeline}.
*/ */
public static Timeline runUntilTimelineChanged( public static Timeline runUntilTimelineChanged(
SimpleExoPlayer player, @Nullable Timeline expectedTimeline) { Player player, @Nullable Timeline expectedTimeline) {
verifyMainTestThread(player); verifyMainTestThread(player);
if (expectedTimeline != null && expectedTimeline.equals(player.getCurrentTimeline())) { if (expectedTimeline != null && expectedTimeline.equals(player.getCurrentTimeline())) {
...@@ -394,7 +394,7 @@ public class TestExoPlayer { ...@@ -394,7 +394,7 @@ public class TestExoPlayer {
* Player.DiscontinuityReason}. * Player.DiscontinuityReason}.
*/ */
public static void runUntilPositionDiscontinuity( public static void runUntilPositionDiscontinuity(
SimpleExoPlayer player, @Player.DiscontinuityReason int expectedReason) { Player player, @Player.DiscontinuityReason int expectedReason) {
AtomicBoolean receivedCallback = new AtomicBoolean(false); AtomicBoolean receivedCallback = new AtomicBoolean(false);
Player.EventListener listener = Player.EventListener listener =
new Player.EventListener() { new Player.EventListener() {
...@@ -414,10 +414,10 @@ public class TestExoPlayer { ...@@ -414,10 +414,10 @@ public class TestExoPlayer {
* Run tasks of the main {@link Looper} until the {@code player} calls the {@link * Run tasks of the main {@link Looper} until the {@code player} calls the {@link
* Player.EventListener#onPlayerError} callback. * Player.EventListener#onPlayerError} callback.
* *
* @param player The {@link SimpleExoPlayer}. * @param player The {@link Player}.
* @return The raised error. * @return The raised error.
*/ */
public static ExoPlaybackException runUntilError(SimpleExoPlayer player) { public static ExoPlaybackException runUntilError(Player player) {
verifyMainTestThread(player); verifyMainTestThread(player);
AtomicReference<ExoPlaybackException> receivedError = new AtomicReference<>(); AtomicReference<ExoPlaybackException> receivedError = new AtomicReference<>();
Player.EventListener listener = Player.EventListener listener =
...@@ -456,7 +456,7 @@ public class TestExoPlayer { ...@@ -456,7 +456,7 @@ public class TestExoPlayer {
* Runs tasks of the main {@link Looper} until the {@code player} handled all previously issued * Runs tasks of the main {@link Looper} until the {@code player} handled all previously issued
* commands completely on the internal playback thread. * commands completely on the internal playback thread.
*/ */
public static void runUntilPendingCommandsAreFullyHandled(SimpleExoPlayer player) { public static void runUntilPendingCommandsAreFullyHandled(ExoPlayer player) {
verifyMainTestThread(player); verifyMainTestThread(player);
// Send message to player that will arrive after all other pending commands. Thus, the message // Send message to player that will arrive after all other pending commands. Thus, the message
// execution on the app thread will also happen after all other pending command // execution on the app thread will also happen after all other pending command
...@@ -484,7 +484,7 @@ public class TestExoPlayer { ...@@ -484,7 +484,7 @@ public class TestExoPlayer {
} }
} }
private static void verifyMainTestThread(SimpleExoPlayer player) { private static void verifyMainTestThread(Player player) {
if (Looper.myLooper() != Looper.getMainLooper() if (Looper.myLooper() != Looper.getMainLooper()
|| player.getApplicationLooper() != Looper.getMainLooper()) { || player.getApplicationLooper() != Looper.getMainLooper()) {
throw new IllegalStateException(); throw new IllegalStateException();
......
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