Commit 0de938c4 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 ec96e0c4
...@@ -32,6 +32,9 @@ ...@@ -32,6 +32,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)).
......
...@@ -1696,37 +1696,43 @@ public final class DefaultAudioSink implements AudioSink { ...@@ -1696,37 +1696,43 @@ 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 == DefaultAudioSink.this.audioTrack); new AudioTrack.StreamEventCallback() {
if (listener != null) { @Override
listener.onOffloadBufferEmptying(); public void onDataRequest(AudioTrack track, int size) {
} Assertions.checkState(track == DefaultAudioSink.this.audioTrack);
} if (listener != null) {
listener.onOffloadBufferEmptying();
@Override }
public void onTearDown(@NonNull AudioTrack track) { }
if (listener != null && playing) {
// A new Audio Track needs to be created and it's buffer filled, which will be done on the @Override
// next handleBuffer call. public void onTearDown(@NonNull AudioTrack track) {
// Request this call explicitly in case ExoPlayer is sleeping waiting for a data request. if (listener != null && playing) {
listener.onOffloadBufferEmptying(); // A new Audio Track needs to be created and it's 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