Skip to content

Commit

Permalink
Revert "fix(android): video flickering add playback start (#3746)" (#…
Browse files Browse the repository at this point in the history
…3748)

This reverts commit b1cd52b.

s
  • Loading branch information
ZakirBangash authored May 10, 2024
1 parent aef7879 commit d25629b
Showing 1 changed file with 19 additions and 22 deletions.
41 changes: 19 additions & 22 deletions android/src/main/java/com/brentvatne/exoplayer/ExoPlayerView.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.brentvatne.exoplayer;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.media3.common.AdViewProvider;
import androidx.media3.common.C;
import androidx.media3.common.PlaybackException;
import androidx.media3.common.PlaybackParameters;
import androidx.media3.common.Player;
import androidx.media3.common.Timeline;
import androidx.media3.common.Tracks;
import androidx.media3.common.VideoSize;
import androidx.media3.common.text.Cue;
Expand Down Expand Up @@ -37,8 +38,8 @@ public final class ExoPlayerView extends FrameLayout implements AdViewProvider {
private final AspectRatioFrameLayout layout;
private final ComponentListener componentListener;
private ExoPlayer player;
final private Context context;
final private ViewGroup.LayoutParams layoutParams;
private Context context;
private ViewGroup.LayoutParams layoutParams;
private final FrameLayout adOverlayFrameLayout;

private boolean useTextureView = true;
Expand Down Expand Up @@ -112,7 +113,7 @@ public boolean isPlaying() {
}

public void setSubtitleStyle(SubtitleStyle style) {
// ensure we reset subtitle style before reapplying it
// ensure we reset subtile style before reapplying it
subtitleLayout.setUserDefaultStyle();
subtitleLayout.setUserDefaultTextSize();

Expand Down Expand Up @@ -210,6 +211,16 @@ public void setResizeMode(@ResizeMode.Mode int resizeMode) {
}
}

/**
* Get the view onto which video is rendered. This is either a {@link SurfaceView} (default)
* or a {@link TextureView} if the {@code use_texture_view} view attribute has been set to true.
*
* @return either a {@link SurfaceView} or a {@link TextureView}.
*/
public View getVideoSurfaceView() {
return surfaceView;
}

public void setUseTextureView(boolean useTextureView) {
if (useTextureView != this.useTextureView) {
this.useTextureView = useTextureView;
Expand Down Expand Up @@ -252,24 +263,15 @@ private void updateForCurrentTrackSelections() {
shutterView.setVisibility(this.hideShutterView ? View.INVISIBLE : View.VISIBLE);
}

Runnable hideShutterViewRunnable = new Runnable() {
@Override
public void run() {
shutterView.setVisibility(INVISIBLE);
}
};

public void invalidateAspectRatio() {
// Resetting aspect ratio will force layout refresh on next video size changed
layout.invalidateAspectRatio();

removeCallbacks(hideShutterViewRunnable);
}

private final class ComponentListener implements Player.Listener {

@Override
public void onCues(@NonNull List<Cue> cues) {
public void onCues(List<Cue> cues) {
subtitleLayout.setCues(cues);
}

Expand All @@ -286,16 +288,11 @@ public void onVideoSizeChanged(VideoSize videoSize) {

@Override
public void onRenderedFirstFrame() {
// The shutter view is use to hide dirty resizing issue when starting playback.
// In case video doesn't match your View aspect ratio, at playback startup you may have flickering during resize.
// we saw that onRenderedFirstFrame is called before first resizing
// Then hiding the shutterView directly may not hide the flickering.
// This small delay avoid the flickering
postDelayed(hideShutterViewRunnable, 15);
shutterView.setVisibility(INVISIBLE);
}

@Override
public void onTracksChanged(@NonNull Tracks tracks) {
public void onTracksChanged(Tracks tracks) {
updateForCurrentTrackSelections();
}
}
Expand Down

0 comments on commit d25629b

Please sign in to comment.