Rasul
Rasul

Reputation: 792

MotionLayout with Exoplayer handle touch events not properly

I have OnSwipe animation in Motion Layout and a ExoPlayer. But when exoplayer is playing, motion layout animation not working. I think ExoPlayer intercepting touch events. How can i solve this issue? For example Youtube application handle swipe and also click events

Upvotes: 1

Views: 859

Answers (2)

aliftc12
aliftc12

Reputation: 310

I solved that problem by creating custom player view. The problem is PlayerView intercepting the touch event, so motion layout don't get any touch event. By changing return value at PlayerView.onTouchEvent from true to false, the motion layout can handle the swipe event.

internal class CustomExoPlayerView(
    context: Context, attributeSet: AttributeSet? = null
) : PlayerView(context, attributeSet) {

    @SuppressLint("ClickableViewAccessibility")
    override fun onTouchEvent(event: MotionEvent): Boolean {
        when (event.action) {
            MotionEvent.ACTION_DOWN -> {
                showController()
            }
        }
        return false
    }
}

Upvotes: 0

sourav sharma
sourav sharma

Reputation: 19

There is a simple Way of doing that Extends the MotionLayout class and by overriding the

onInterceptTouchEvent()

 @Override
    public boolean onInterceptTouchEvent(MotionEvent event) {
        if (onTouchEvent(event)) {
            return false;
        } else {
            return true;
        }
    }

this is a simplest way to pass Childs touch event to parent or to background layout. this will resolve your issue.

Upvotes: 2

Related Questions