Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle properly player controls click #9862

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import android.opengl.GLSurfaceView;
import android.os.Looper;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
Expand All @@ -45,6 +46,7 @@
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.core.content.ContextCompat;
import androidx.core.view.GestureDetectorCompat;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.MediaMetadata;
import com.google.android.exoplayer2.PlaybackException;
Expand Down Expand Up @@ -280,6 +282,7 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
private static final int SURFACE_TYPE_VIDEO_DECODER_GL_SURFACE_VIEW = 4;

private final ComponentListener componentListener;
private final GestureDetectorCompat gestureDetector;
@Nullable private final AspectRatioFrameLayout contentFrame;
@Nullable private final View shutterView;
@Nullable private final View surfaceView;
Expand All @@ -306,7 +309,6 @@ public class PlayerView extends FrameLayout implements AdViewProvider {
private boolean controllerHideDuringAds;
private boolean controllerHideOnTouch;
private int textureViewRotation;
private boolean isTouching;
private static final int PICTURE_TYPE_FRONT_COVER = 3;
private static final int PICTURE_TYPE_NOT_SET = -1;

Expand All @@ -323,6 +325,21 @@ public PlayerView(Context context, @Nullable AttributeSet attrs, int defStyleAtt
super(context, attrs, defStyleAttr);

componentListener = new ComponentListener();
gestureDetector = new GestureDetectorCompat(
getContext(),
new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onDown(MotionEvent e) {
return true;
}

@Override
public boolean onSingleTapUp(MotionEvent e) {
performClick();
return true;
}
}
);

if (isInEditMode()) {
contentFrame = null;
Expand Down Expand Up @@ -1068,25 +1085,14 @@ public SubtitleView getSubtitleView() {
return subtitleView;
}

// performClick handled by GestureDetector
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent event) {
if (!useController() || player == null) {
return false;
}
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
isTouching = true;
return true;
case MotionEvent.ACTION_UP:
if (isTouching) {
isTouching = false;
performClick();
return true;
}
return false;
default:
return false;
}
return gestureDetector.onTouchEvent(event);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import android.opengl.GLSurfaceView;
import android.os.Looper;
import android.util.AttributeSet;
import android.view.GestureDetector;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
Expand All @@ -46,6 +47,7 @@
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.core.content.ContextCompat;
import androidx.core.view.GestureDetectorCompat;
import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.MediaMetadata;
import com.google.android.exoplayer2.PlaybackException;
Expand Down Expand Up @@ -281,6 +283,7 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
private static final int SURFACE_TYPE_VIDEO_DECODER_GL_SURFACE_VIEW = 4;

private final ComponentListener componentListener;
private final GestureDetectorCompat gestureDetector;
@Nullable private final AspectRatioFrameLayout contentFrame;
@Nullable private final View shutterView;
@Nullable private final View surfaceView;
Expand All @@ -307,7 +310,6 @@ public class StyledPlayerView extends FrameLayout implements AdViewProvider {
private boolean controllerHideDuringAds;
private boolean controllerHideOnTouch;
private int textureViewRotation;
private boolean isTouching;
private static final int PICTURE_TYPE_FRONT_COVER = 3;
private static final int PICTURE_TYPE_NOT_SET = -1;

Expand All @@ -324,6 +326,21 @@ public StyledPlayerView(Context context, @Nullable AttributeSet attrs, int defSt
super(context, attrs, defStyleAttr);

componentListener = new ComponentListener();
gestureDetector = new GestureDetectorCompat(
getContext(),
new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onDown(MotionEvent e) {
return true;
}

@Override
public boolean onSingleTapUp(MotionEvent e) {
performClick();
return true;
}
}
);

if (isInEditMode()) {
contentFrame = null;
Expand Down Expand Up @@ -1105,24 +1122,14 @@ public SubtitleView getSubtitleView() {
return subtitleView;
}

// performClick handled by GestureDetector
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent event) {
if (!useController() || player == null) {
return false;
}
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
isTouching = true;
return true;
case MotionEvent.ACTION_UP:
if (isTouching) {
isTouching = false;
return performClick();
}
return false;
default:
return false;
}
return gestureDetector.onTouchEvent(event);
}

@Override
Expand Down