Toggle playback controls according to standard Android click handling.

We currently toggle the view in onTouchEvent ACTION_DOWN which is non-standard
and causes problems when used in a ViewGroup intercepting touch events.

Switch to standard Android click handling instead which is also what most
other player apps are doing.

Issue:#5784
PiperOrigin-RevId: 245219728
This commit is contained in:
tonihei 2019-04-25 13:48:36 +01:00 committed by Oliver Woodman
parent b9f3fd429d
commit 25e93a178a
2 changed files with 17 additions and 4 deletions

View File

@ -8,6 +8,8 @@
* UI: * UI:
* Allow setting `DefaultTimeBar` attributes on `PlayerView` and * Allow setting `DefaultTimeBar` attributes on `PlayerView` and
`PlayerControlView`. `PlayerControlView`.
* Change playback controls toggle from touch down to touch up events
([#5784](https://github.com/google/ExoPlayer/issues/5784)).
* Fix issue where playback controls were not kept visible on key presses * Fix issue where playback controls were not kept visible on key presses
([#5963](https://github.com/google/ExoPlayer/issues/5963)). ([#5963](https://github.com/google/ExoPlayer/issues/5963)).
* Add a playWhenReady flag to MediaSessionConnector.PlaybackPreparer methods * Add a playWhenReady flag to MediaSessionConnector.PlaybackPreparer methods

View File

@ -303,6 +303,7 @@ public class PlayerView extends FrameLayout implements AdsLoader.AdViewProvider
private boolean controllerHideDuringAds; private boolean controllerHideDuringAds;
private boolean controllerHideOnTouch; private boolean controllerHideOnTouch;
private int textureViewRotation; private int textureViewRotation;
private boolean isTouching;
public PlayerView(Context context) { public PlayerView(Context context) {
this(context, null); this(context, null);
@ -1048,11 +1049,21 @@ public class PlayerView extends FrameLayout implements AdsLoader.AdViewProvider
} }
@Override @Override
public boolean onTouchEvent(MotionEvent ev) { public boolean onTouchEvent(MotionEvent event) {
if (ev.getActionMasked() != MotionEvent.ACTION_DOWN) { switch (event.getAction()) {
return false; 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 performClick();
} }
@Override @Override