Allow stable API users to use DebugTextViewHelper
This is used from the main demo app. PiperOrigin-RevId: 445420580
This commit is contained in:
parent
b0df946f67
commit
b9a8da4e3e
@ -28,12 +28,13 @@ import java.util.Locale;
|
||||
* A helper class for periodically updating a {@link TextView} with debug information obtained from
|
||||
* an {@link ExoPlayer}.
|
||||
*/
|
||||
public class DebugTextViewHelper implements Player.Listener, Runnable {
|
||||
public class DebugTextViewHelper {
|
||||
|
||||
private static final int REFRESH_INTERVAL_MS = 1000;
|
||||
|
||||
private final ExoPlayer player;
|
||||
private final TextView textView;
|
||||
private final Updater updater;
|
||||
|
||||
private boolean started;
|
||||
|
||||
@ -47,6 +48,7 @@ public class DebugTextViewHelper implements Player.Listener, Runnable {
|
||||
Assertions.checkArgument(player.getApplicationLooper() == Looper.getMainLooper());
|
||||
this.player = player;
|
||||
this.textView = textView;
|
||||
this.updater = new Updater();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -58,7 +60,7 @@ public class DebugTextViewHelper implements Player.Listener, Runnable {
|
||||
return;
|
||||
}
|
||||
started = true;
|
||||
player.addListener(this);
|
||||
player.addListener(updater);
|
||||
updateAndPost();
|
||||
}
|
||||
|
||||
@ -71,36 +73,8 @@ public class DebugTextViewHelper implements Player.Listener, Runnable {
|
||||
return;
|
||||
}
|
||||
started = false;
|
||||
player.removeListener(this);
|
||||
textView.removeCallbacks(this);
|
||||
}
|
||||
|
||||
// Player.Listener implementation.
|
||||
|
||||
@Override
|
||||
public final void onPlaybackStateChanged(@Player.State int playbackState) {
|
||||
updateAndPost();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onPlayWhenReadyChanged(
|
||||
boolean playWhenReady, @Player.PlayWhenReadyChangeReason int reason) {
|
||||
updateAndPost();
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void onPositionDiscontinuity(
|
||||
Player.PositionInfo oldPosition,
|
||||
Player.PositionInfo newPosition,
|
||||
@Player.DiscontinuityReason int reason) {
|
||||
updateAndPost();
|
||||
}
|
||||
|
||||
// Runnable implementation.
|
||||
|
||||
@Override
|
||||
public final void run() {
|
||||
updateAndPost();
|
||||
player.removeListener(updater);
|
||||
textView.removeCallbacks(updater);
|
||||
}
|
||||
|
||||
// Protected methods.
|
||||
@ -108,8 +82,8 @@ public class DebugTextViewHelper implements Player.Listener, Runnable {
|
||||
@SuppressLint("SetTextI18n")
|
||||
protected final void updateAndPost() {
|
||||
textView.setText(getDebugString());
|
||||
textView.removeCallbacks(this);
|
||||
textView.postDelayed(this, REFRESH_INTERVAL_MS);
|
||||
textView.removeCallbacks(updater);
|
||||
textView.postDelayed(updater, REFRESH_INTERVAL_MS);
|
||||
}
|
||||
|
||||
/** Returns the debugging information string to be shown by the target {@link TextView}. */
|
||||
@ -219,4 +193,35 @@ public class DebugTextViewHelper implements Player.Listener, Runnable {
|
||||
return String.valueOf(averageUs);
|
||||
}
|
||||
}
|
||||
|
||||
private final class Updater implements Player.Listener, Runnable {
|
||||
|
||||
// Player.Listener implementation.
|
||||
|
||||
@Override
|
||||
public void onPlaybackStateChanged(@Player.State int playbackState) {
|
||||
updateAndPost();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayWhenReadyChanged(
|
||||
boolean playWhenReady, @Player.PlayWhenReadyChangeReason int reason) {
|
||||
updateAndPost();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPositionDiscontinuity(
|
||||
Player.PositionInfo oldPosition,
|
||||
Player.PositionInfo newPosition,
|
||||
@Player.DiscontinuityReason int reason) {
|
||||
updateAndPost();
|
||||
}
|
||||
|
||||
// Runnable implementation.
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
updateAndPost();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user