Remove AnalyticsListener
as a public super-type of ExoHostedTest
Move the `AnalyticsListener` implementation to a private inner class. This avoids polluting the public API of `ExoHostedTest`, especially as it's designed to be extended. PiperOrigin-RevId: 589188113
This commit is contained in:
parent
ac67f739d4
commit
224dad3988
@ -46,7 +46,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
|
||||
/** A {@link HostedTest} for {@link ExoPlayer} playback tests. */
|
||||
@UnstableApi
|
||||
public abstract class ExoHostedTest implements AnalyticsListener, HostedTest {
|
||||
public abstract class ExoHostedTest implements HostedTest {
|
||||
|
||||
static {
|
||||
// DefaultAudioSink is able to work around spurious timestamps reported by the platform (by
|
||||
@ -137,7 +137,7 @@ public abstract class ExoHostedTest implements AnalyticsListener, HostedTest {
|
||||
trackSelector = buildTrackSelector(host);
|
||||
player = buildExoPlayer(host, surface, trackSelector);
|
||||
player.play();
|
||||
player.addAnalyticsListener(this);
|
||||
player.addAnalyticsListener(new AnalyticsListenerImpl());
|
||||
player.addAnalyticsListener(new EventLogger(tag));
|
||||
// Schedule any pending actions.
|
||||
actionHandler =
|
||||
@ -186,41 +186,6 @@ public abstract class ExoHostedTest implements AnalyticsListener, HostedTest {
|
||||
assertPassed(audioDecoderCounters, videoDecoderCounters);
|
||||
}
|
||||
|
||||
// AnalyticsListener
|
||||
|
||||
@Override
|
||||
public void onEvents(Player player, Events events) {
|
||||
if (events.contains(EVENT_IS_PLAYING_CHANGED)) {
|
||||
if (player.isPlaying()) {
|
||||
lastPlayingStartTimeMs = SystemClock.elapsedRealtime();
|
||||
} else {
|
||||
totalPlayingTimeMs += SystemClock.elapsedRealtime() - lastPlayingStartTimeMs;
|
||||
}
|
||||
}
|
||||
if (events.contains(EVENT_PLAYER_ERROR)) {
|
||||
// The exception is guaranteed to be an ExoPlaybackException because the underlying player is
|
||||
// an ExoPlayer instance.
|
||||
playerError = (ExoPlaybackException) checkNotNull(player.getPlayerError());
|
||||
onPlayerErrorInternal(playerError);
|
||||
}
|
||||
if (events.contains(EVENT_PLAYBACK_STATE_CHANGED)) {
|
||||
@Player.State int playbackState = player.getPlaybackState();
|
||||
if (playbackState == Player.STATE_ENDED || playbackState == Player.STATE_IDLE) {
|
||||
stopTest();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAudioDisabled(EventTime eventTime, DecoderCounters decoderCounters) {
|
||||
audioDecoderCounters.merge(decoderCounters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVideoDisabled(EventTime eventTime, DecoderCounters decoderCounters) {
|
||||
videoDecoderCounters.merge(decoderCounters);
|
||||
}
|
||||
|
||||
// Internal logic
|
||||
|
||||
private boolean stopTest() {
|
||||
@ -283,4 +248,39 @@ public abstract class ExoHostedTest implements AnalyticsListener, HostedTest {
|
||||
Util.castNonNull(surface);
|
||||
return true;
|
||||
}
|
||||
|
||||
private final class AnalyticsListenerImpl implements AnalyticsListener {
|
||||
@Override
|
||||
public void onEvents(Player player, Events events) {
|
||||
if (events.contains(EVENT_IS_PLAYING_CHANGED)) {
|
||||
if (player.isPlaying()) {
|
||||
lastPlayingStartTimeMs = SystemClock.elapsedRealtime();
|
||||
} else {
|
||||
totalPlayingTimeMs += SystemClock.elapsedRealtime() - lastPlayingStartTimeMs;
|
||||
}
|
||||
}
|
||||
if (events.contains(EVENT_PLAYER_ERROR)) {
|
||||
// The exception is guaranteed to be an ExoPlaybackException because the underlying player
|
||||
// is an ExoPlayer instance.
|
||||
playerError = (ExoPlaybackException) checkNotNull(player.getPlayerError());
|
||||
onPlayerErrorInternal(playerError);
|
||||
}
|
||||
if (events.contains(EVENT_PLAYBACK_STATE_CHANGED)) {
|
||||
@Player.State int playbackState = player.getPlaybackState();
|
||||
if (playbackState == Player.STATE_ENDED || playbackState == Player.STATE_IDLE) {
|
||||
stopTest();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAudioDisabled(EventTime eventTime, DecoderCounters decoderCounters) {
|
||||
audioDecoderCounters.merge(decoderCounters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onVideoDisabled(EventTime eventTime, DecoderCounters decoderCounters) {
|
||||
videoDecoderCounters.merge(decoderCounters);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user