Commit 515fdf3b by aquilescanta Committed by Oliver Woodman

Allow extension of DebugTextViewHelper

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=181970955
parent cfed8791
...@@ -27,7 +27,7 @@ import java.util.Locale; ...@@ -27,7 +27,7 @@ import java.util.Locale;
* A helper class for periodically updating a {@link TextView} with debug information obtained from * A helper class for periodically updating a {@link TextView} with debug information obtained from
* a {@link SimpleExoPlayer}. * a {@link SimpleExoPlayer}.
*/ */
public final class DebugTextViewHelper extends Player.DefaultEventListener implements Runnable { public class DebugTextViewHelper extends Player.DefaultEventListener implements Runnable {
private static final int REFRESH_INTERVAL_MS = 1000; private static final int REFRESH_INTERVAL_MS = 1000;
...@@ -49,7 +49,7 @@ public final class DebugTextViewHelper extends Player.DefaultEventListener imple ...@@ -49,7 +49,7 @@ public final class DebugTextViewHelper extends Player.DefaultEventListener imple
* Starts periodic updates of the {@link TextView}. Must be called from the application's main * Starts periodic updates of the {@link TextView}. Must be called from the application's main
* thread. * thread.
*/ */
public void start() { public final void start() {
if (started) { if (started) {
return; return;
} }
...@@ -62,7 +62,7 @@ public final class DebugTextViewHelper extends Player.DefaultEventListener imple ...@@ -62,7 +62,7 @@ public final class DebugTextViewHelper extends Player.DefaultEventListener imple
* Stops periodic updates of the {@link TextView}. Must be called from the application's main * Stops periodic updates of the {@link TextView}. Must be called from the application's main
* thread. * thread.
*/ */
public void stop() { public final void stop() {
if (!started) { if (!started) {
return; return;
} }
...@@ -74,59 +74,63 @@ public final class DebugTextViewHelper extends Player.DefaultEventListener imple ...@@ -74,59 +74,63 @@ public final class DebugTextViewHelper extends Player.DefaultEventListener imple
// Player.EventListener implementation. // Player.EventListener implementation.
@Override @Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) { public final void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
updateAndPost(); updateAndPost();
} }
@Override @Override
public void onPositionDiscontinuity(@Player.DiscontinuityReason int reason) { public final void onPositionDiscontinuity(@Player.DiscontinuityReason int reason) {
updateAndPost(); updateAndPost();
} }
// Runnable implementation. // Runnable implementation.
@Override @Override
public void run() { public final void run() {
updateAndPost(); updateAndPost();
} }
// Private methods. // Protected methods.
@SuppressLint("SetTextI18n") @SuppressLint("SetTextI18n")
private void updateAndPost() { protected final void updateAndPost() {
textView.setText(getPlayerStateString() + getPlayerWindowIndexString() + getVideoString() textView.setText(getDebugString());
+ getAudioString());
textView.removeCallbacks(this); textView.removeCallbacks(this);
textView.postDelayed(this, REFRESH_INTERVAL_MS); textView.postDelayed(this, REFRESH_INTERVAL_MS);
} }
private String getPlayerStateString() { /** Returns the debugging information string to be shown by the target {@link TextView}. */
String text = "playWhenReady:" + player.getPlayWhenReady() + " playbackState:"; protected String getDebugString() {
return getPlayerStateString() + getVideoString() + getAudioString();
}
/** Returns a string containing player state debugging information. */
protected String getPlayerStateString() {
String playbackStateString;
switch (player.getPlaybackState()) { switch (player.getPlaybackState()) {
case Player.STATE_BUFFERING: case Player.STATE_BUFFERING:
text += "buffering"; playbackStateString = "buffering";
break; break;
case Player.STATE_ENDED: case Player.STATE_ENDED:
text += "ended"; playbackStateString = "ended";
break; break;
case Player.STATE_IDLE: case Player.STATE_IDLE:
text += "idle"; playbackStateString = "idle";
break; break;
case Player.STATE_READY: case Player.STATE_READY:
text += "ready"; playbackStateString = "ready";
break; break;
default: default:
text += "unknown"; playbackStateString = "unknown";
break; break;
} }
return text; return String.format(
} "playWhenReady:%s playbackState:%s window:%s",
player.getPlayWhenReady(), playbackStateString, player.getCurrentWindowIndex());
private String getPlayerWindowIndexString() {
return " window:" + player.getCurrentWindowIndex();
} }
private String getVideoString() { /** Returns a string containing video debugging information. */
protected String getVideoString() {
Format format = player.getVideoFormat(); Format format = player.getVideoFormat();
if (format == null) { if (format == null) {
return ""; return "";
...@@ -136,7 +140,8 @@ public final class DebugTextViewHelper extends Player.DefaultEventListener imple ...@@ -136,7 +140,8 @@ public final class DebugTextViewHelper extends Player.DefaultEventListener imple
+ getDecoderCountersBufferCountString(player.getVideoDecoderCounters()) + ")"; + getDecoderCountersBufferCountString(player.getVideoDecoderCounters()) + ")";
} }
private String getAudioString() { /** Returns a string containing audio debugging information. */
protected String getAudioString() {
Format format = player.getAudioFormat(); Format format = player.getAudioFormat();
if (format == null) { if (format == null) {
return ""; return "";
......
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