Commit 230f4e5b by krocard Committed by Oliver Woodman

Do not inherit directly from AudioTrack.StreamEventCallback

This was causing issues old devices where the class
inheriting StreamEventCallback was loaded even though
it was not used.

Instead use an anonymous class that seem to be loaded
more lazily.

PiperOrigin-RevId: 337252687
parent bb851c99
...@@ -48,6 +48,9 @@ ...@@ -48,6 +48,9 @@
* Fix the default audio sink position not advancing correctly when using * Fix the default audio sink position not advancing correctly when using
`AudioTrack`-based speed adjustment `AudioTrack`-based speed adjustment
([#7982](https://github.com/google/ExoPlayer/issues/7982)). ([#7982](https://github.com/google/ExoPlayer/issues/7982)).
* Fix `NoClassDefFoundError` warning for `AudioTrack$StreamEventCallback`
even though the class was not used
([#8058](https://github.com/google/ExoPlayer/issues/8058)).
* Extractors: * Extractors:
* Add support for .mp2 boxes in the `AtomParsers` * Add support for .mp2 boxes in the `AtomParsers`
([#7967](https://github.com/google/ExoPlayer/issues/7967)). ([#7967](https://github.com/google/ExoPlayer/issues/7967)).
......
...@@ -1731,39 +1731,47 @@ public final class DefaultAudioSink implements AudioSink { ...@@ -1731,39 +1731,47 @@ public final class DefaultAudioSink implements AudioSink {
} }
@RequiresApi(29) @RequiresApi(29)
private final class StreamEventCallbackV29 extends AudioTrack.StreamEventCallback { private final class StreamEventCallbackV29 {
private final Handler handler; private final Handler handler;
private final AudioTrack.StreamEventCallback callback;
public StreamEventCallbackV29() { public StreamEventCallbackV29() {
handler = new Handler(); handler = new Handler();
} // StreamEventCallbackV29 can NOT inherit directly from AudioTrack.StreamEventCallback as it
// would cause a NoClassDefFoundError on the first load of DefaultAudioSink for SDK < 29
@Override // fatal on some devices. See: https://github.com/google/ExoPlayer/issues/8058
public void onDataRequest(AudioTrack track, int size) { callback =
Assertions.checkState(track == audioTrack); new AudioTrack.StreamEventCallback() {
if (listener != null && playing) { @Override
// Do not signal that the buffer is emptying if not playing as it is a transient state. public void onDataRequest(AudioTrack track, int size) {
listener.onOffloadBufferEmptying(); Assertions.checkState(track == audioTrack);
} if (listener != null && playing) {
} // Do not signal that the buffer is emptying if not playing as it is a transient
// state.
@Override listener.onOffloadBufferEmptying();
public void onTearDown(@NonNull AudioTrack track) { }
Assertions.checkState(track == audioTrack); }
if (listener != null && playing) {
// The audio track was destroyed while in use. Thus a new AudioTrack needs to be created @Override
// and its buffer filled, which will be done on the next handleBuffer call. public void onTearDown(@NonNull AudioTrack track) {
// Request this call explicitly in case ExoPlayer is sleeping waiting for a data request. Assertions.checkState(track == audioTrack);
listener.onOffloadBufferEmptying(); if (listener != null && playing) {
} // The audio track was destroyed while in use. Thus a new AudioTrack needs to be
// created and its buffer filled, which will be done on the next handleBuffer call.
// Request this call explicitly in case ExoPlayer is sleeping waiting for a data
// request.
listener.onOffloadBufferEmptying();
}
}
};
} }
public void register(AudioTrack audioTrack) { public void register(AudioTrack audioTrack) {
audioTrack.registerStreamEventCallback(handler::post, this); audioTrack.registerStreamEventCallback(handler::post, callback);
} }
public void unregister(AudioTrack audioTrack) { public void unregister(AudioTrack audioTrack) {
audioTrack.unregisterStreamEventCallback(this); audioTrack.unregisterStreamEventCallback(callback);
handler.removeCallbacksAndMessages(/* token= */ null); handler.removeCallbacksAndMessages(/* token= */ null);
} }
} }
......
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