From d716e1ab2aba09028dbffa8bf17eb6caac2146fd Mon Sep 17 00:00:00 2001 From: Olivier Bouillet <62574056+freeboub@users.noreply.github.com> Date: Fri, 17 May 2024 15:10:37 +0200 Subject: [PATCH] chore(android): improve exoplayer logs (#3780) * perf: ensure we do not provide callback to native if no callback provided from app * chore: rework bufferConfig to make it more generic and reduce ReactExoplayerView code size * chore: improve issue template * fix(android): avoid video view flickering at playback startup * fix: improve debuging display and enable it in the sample --- .../exoplayer/ReactExoplayerView.java | 25 +++++++++++++++++++ .../exoplayer/ReactExoplayerViewManager.java | 1 + examples/basic/src/VideoPlayer.tsx | 1 + 3 files changed, 27 insertions(+) diff --git a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java index ffccdaa8..76ca9811 100644 --- a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java +++ b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java @@ -97,6 +97,7 @@ import androidx.media3.exoplayer.trackselection.TrackSelectionArray; import androidx.media3.exoplayer.upstream.BandwidthMeter; import androidx.media3.exoplayer.upstream.DefaultAllocator; import androidx.media3.exoplayer.upstream.DefaultBandwidthMeter; +import androidx.media3.exoplayer.util.EventLogger; import androidx.media3.extractor.metadata.emsg.EventMessage; import androidx.media3.extractor.metadata.id3.Id3Frame; import androidx.media3.extractor.metadata.id3.TextInformationFrame; @@ -185,6 +186,11 @@ public class ReactExoplayerView extends FrameLayout implements private ServiceConnection playbackServiceConnection; private PlaybackServiceBinder playbackServiceBinder; + // logger to be enable by props + private EventLogger debugEventLogger = null; + private boolean enableDebug = false; + private static final String TAG_EVENT_LOGGER = "RNVExoplayer"; + private int resumeWindow; private long resumePosition; private boolean loadVideoStarted; @@ -508,6 +514,24 @@ public class ReactExoplayerView extends FrameLayout implements reLayout(playerControlView); } + public void setDebug(boolean enableDebug) { + this.enableDebug = enableDebug; + refreshDebugState(); + } + + private void refreshDebugState() { + if (player == null) { + return; + } + if (enableDebug) { + debugEventLogger = new EventLogger(TAG_EVENT_LOGGER); + player.addAnalyticsListener(debugEventLogger); + } else if (debugEventLogger != null) { + player.removeAnalyticsListener(debugEventLogger); + debugEventLogger = null; + } + } + private class RNVLoadControl extends DefaultLoadControl { private final int availableHeapInBytes; private final Runtime runtime; @@ -666,6 +690,7 @@ public class ReactExoplayerView extends FrameLayout implements .setLoadControl(loadControl) .setMediaSourceFactory(mediaSourceFactory) .build(); + refreshDebugState(); player.addListener(self); player.setVolume(muted ? 0.f : audioVolume * 1); exoPlayerView.setPlayer(player); diff --git a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java index 997a137e..74f818f5 100644 --- a/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java +++ b/android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerViewManager.java @@ -448,6 +448,7 @@ public class ReactExoplayerViewManager extends ViewGroupManager );