Miscellaneous cleanup related to recent changes

PiperOrigin-RevId: 300067561
This commit is contained in:
olly 2020-03-10 12:20:56 +00:00 committed by Oliver Woodman
parent b83041a6f5
commit 0d230d517a
3 changed files with 36 additions and 38 deletions

View File

@ -177,7 +177,7 @@ public class SampleChooserActivity extends AppCompatActivity
groupPosition = preferences.getInt(GROUP_POSITION_PREFERENCE_KEY, /* defValue= */ -1); groupPosition = preferences.getInt(GROUP_POSITION_PREFERENCE_KEY, /* defValue= */ -1);
childPosition = preferences.getInt(CHILD_POSITION_PREFERENCE_KEY, /* defValue= */ -1); childPosition = preferences.getInt(CHILD_POSITION_PREFERENCE_KEY, /* defValue= */ -1);
} catch (ClassCastException e) { } catch (ClassCastException e) {
android.util.Log.w(TAG, "Saved position is not an int. Will not restore position.", e); Log.w(TAG, "Saved position is not an int. Will not restore position.", e);
} }
if (groupPosition != -1 && childPosition != -1) { if (groupPosition != -1 && childPosition != -1) {
sampleListView.expandGroup(groupPosition); // shouldExpandGroup does not work without this. sampleListView.expandGroup(groupPosition); // shouldExpandGroup does not work without this.

View File

@ -1704,6 +1704,20 @@ public class SimpleExoPlayer extends BasePlayer
} }
} }
@SuppressWarnings("SuspiciousMethodCalls")
private void notifySkipSilenceEnabledChanged() {
for (AudioListener listener : audioListeners) {
// Prevent duplicate notification if a listener is both a AudioRendererEventListener and
// a AudioListener, as they have the same method signature.
if (!audioDebugListeners.contains(listener)) {
listener.onSkipSilenceEnabledChanged(skipSilenceEnabled);
}
}
for (AudioRendererEventListener listener : audioDebugListeners) {
listener.onSkipSilenceEnabledChanged(skipSilenceEnabled);
}
}
private void updatePlayWhenReady( private void updatePlayWhenReady(
boolean playWhenReady, boolean playWhenReady,
@AudioFocusManager.PlayerCommand int playerCommand, @AudioFocusManager.PlayerCommand int playerCommand,
@ -1717,17 +1731,6 @@ public class SimpleExoPlayer extends BasePlayer
player.setPlayWhenReady(playWhenReady, playbackSuppressionReason, playWhenReadyChangeReason); player.setPlayWhenReady(playWhenReady, playbackSuppressionReason, playWhenReadyChangeReason);
} }
private void verifyApplicationThread() {
if (Looper.myLooper() != getApplicationLooper()) {
Log.w(
TAG,
"Player is accessed on the wrong thread. See "
+ "https://exoplayer.dev/issues/player-accessed-on-wrong-thread",
hasNotifiedFullWrongThreadWarning ? null : new IllegalStateException());
hasNotifiedFullWrongThreadWarning = true;
}
}
private void updateWakeAndWifiLock() { private void updateWakeAndWifiLock() {
@State int playbackState = getPlaybackState(); @State int playbackState = getPlaybackState();
switch (playbackState) { switch (playbackState) {
@ -1746,26 +1749,23 @@ public class SimpleExoPlayer extends BasePlayer
} }
} }
private void verifyApplicationThread() {
if (Looper.myLooper() != getApplicationLooper()) {
Log.w(
TAG,
"Player is accessed on the wrong thread. See "
+ "https://exoplayer.dev/issues/player-accessed-on-wrong-thread",
hasNotifiedFullWrongThreadWarning ? null : new IllegalStateException());
hasNotifiedFullWrongThreadWarning = true;
}
}
private static int getPlayWhenReadyChangeReason(boolean playWhenReady, int playerCommand) { private static int getPlayWhenReadyChangeReason(boolean playWhenReady, int playerCommand) {
return playWhenReady && playerCommand != AudioFocusManager.PLAYER_COMMAND_PLAY_WHEN_READY return playWhenReady && playerCommand != AudioFocusManager.PLAYER_COMMAND_PLAY_WHEN_READY
? PLAY_WHEN_READY_CHANGE_REASON_AUDIO_FOCUS_LOSS ? PLAY_WHEN_READY_CHANGE_REASON_AUDIO_FOCUS_LOSS
: PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST; : PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST;
} }
@SuppressWarnings("SuspiciousMethodCalls")
private void notifySkipSilenceEnabledChanged() {
for (AudioListener listener : audioListeners) {
// Prevent duplicate notification if a listener is both a AudioRendererEventListener and
// a AudioListener, as they have the same method signature.
if (!audioDebugListeners.contains(listener)) {
listener.onSkipSilenceEnabledChanged(skipSilenceEnabled);
}
}
for (AudioRendererEventListener listener : audioDebugListeners) {
listener.onSkipSilenceEnabledChanged(skipSilenceEnabled);
}
}
private final class ComponentListener private final class ComponentListener
implements VideoRendererEventListener, implements VideoRendererEventListener,
AudioRendererEventListener, AudioRendererEventListener,

View File

@ -78,15 +78,15 @@ public final class Mp3Extractor implements Extractor {
*/ */
public static final int FLAG_ENABLE_CONSTANT_BITRATE_SEEKING = 1; public static final int FLAG_ENABLE_CONSTANT_BITRATE_SEEKING = 1;
/** /**
* Flag to force index seeking, consisting in building a time-to-byte mapping as the file is read. * Flag to force index seeking, in which a time-to-byte mapping is built as the file is read.
* *
* <p>This seeker may require to scan a significant portion of the file to compute a seek point. * <p>This seeker may require to scan a significant portion of the file to compute a seek point.
* Therefore, it should only be used if: * Therefore, it should only be used if one of the following is true:
* *
* <ul> * <ul>
* <li>the file is small, or * <li>The file is small.
* <li>the bitrate is variable (or the type of bitrate is unknown) and the seeking metadata * <li>The bitrate is variable (or it's unknown whether it's variable) and the file does not
* provided in the file is not precise enough (or is not present). * provide precise enough seeking metadata.
* </ul> * </ul>
*/ */
public static final int FLAG_ENABLE_INDEX_SEEKING = 1 << 1; public static final int FLAG_ENABLE_INDEX_SEEKING = 1 << 1;
@ -135,9 +135,7 @@ public final class Mp3Extractor implements Extractor {
private @MonotonicNonNull ExtractorOutput extractorOutput; private @MonotonicNonNull ExtractorOutput extractorOutput;
private @MonotonicNonNull TrackOutput realTrackOutput; private @MonotonicNonNull TrackOutput realTrackOutput;
// currentTrackOutput is set to skippingTrackOutput or to realTrackOutput, depending if the data private TrackOutput currentTrackOutput; // skippingTrackOutput or realTrackOutput.
// read must be sent to the output.
private @MonotonicNonNull TrackOutput currentTrackOutput;
private int synchronizedHeaderData; private int synchronizedHeaderData;
@ -177,6 +175,7 @@ public final class Mp3Extractor implements Extractor {
basisTimeUs = C.TIME_UNSET; basisTimeUs = C.TIME_UNSET;
id3Peeker = new Id3Peeker(); id3Peeker = new Id3Peeker();
skippingTrackOutput = new DummyTrackOutput(); skippingTrackOutput = new DummyTrackOutput();
currentTrackOutput = skippingTrackOutput;
} }
// Extractor implementation. // Extractor implementation.
@ -238,7 +237,7 @@ public final class Mp3Extractor implements Extractor {
// Internal methods. // Internal methods.
@RequiresNonNull({"extractorOutput", "currentTrackOutput", "realTrackOutput"}) @RequiresNonNull({"extractorOutput", "realTrackOutput"})
private int readInternal(ExtractorInput input) throws IOException { private int readInternal(ExtractorInput input) throws IOException {
if (synchronizedHeaderData == 0) { if (synchronizedHeaderData == 0) {
try { try {
@ -271,7 +270,7 @@ public final class Mp3Extractor implements Extractor {
return readSample(input); return readSample(input);
} }
@RequiresNonNull({"currentTrackOutput", "realTrackOutput", "seeker"}) @RequiresNonNull({"realTrackOutput", "seeker"})
private int readSample(ExtractorInput extractorInput) throws IOException { private int readSample(ExtractorInput extractorInput) throws IOException {
if (sampleBytesRemaining == 0) { if (sampleBytesRemaining == 0) {
extractorInput.resetPeekPosition(); extractorInput.resetPeekPosition();
@ -512,10 +511,9 @@ public final class Mp3Extractor implements Extractor {
return new ConstantBitrateSeeker(input.getLength(), input.getPosition(), synchronizedHeader); return new ConstantBitrateSeeker(input.getLength(), input.getPosition(), synchronizedHeader);
} }
@EnsuresNonNull({"extractorOutput", "currentTrackOutput", "realTrackOutput"}) @EnsuresNonNull({"extractorOutput", "realTrackOutput"})
private void assertInitialized() { private void assertInitialized() {
Assertions.checkStateNotNull(realTrackOutput); Assertions.checkStateNotNull(realTrackOutput);
Util.castNonNull(currentTrackOutput);
Util.castNonNull(extractorOutput); Util.castNonNull(extractorOutput);
} }