0

Context of the Problem


I was currently trying to build a functionality to fast forward videos in ExoPlayer exactly like how Youtube does it. I thought that I could add a double click listener and I was able to do that using the answer given here.

Problem


The problem I am facing is that I was getting the ripple animation even when I do a single click which is not what I want. I want to be able to get a ripple only when a double click is triggered. So, for this, I tried to get the number of clicks and then accordingly set the ripple visibility on the view but it did not seem to work for me and instead giving a weird behaviour. The issue can be seen in the gif given below* :

It can be clearly seen that on single click, it shows ripple. On double click, it shows one ripple right but the other one comes out from nowhere!

Code


  • Kotlin

          var doubleClickLastTime = 0L
          var clicksDone = 0
    
          binding.forward.setOnClickListener {
              if((System.currentTimeMillis() - doubleClickLastTimeF) < 350){
                  doubleClickLastTime = 0
                  clicksDone = 0
                  exoPlayer.seekTo(exoPlayer.contentPosition + 10000)
              }else{
                  if (clicksDoneF == 0){
                      binding.forward.foreground = null
                  }else{
                      binding.forward.foreground = with(TypedValue()) {
                          this@VideoPlayer.theme.resolveAttribute(
                              android.R.attr.selectableItemBackground, this, true)
                          ContextCompat.getDrawable(this@VideoPlayerFromUrl, resourceId)
                      }
                  }
                  clicksDone++
                  doubleClickLastTime = System.currentTimeMillis()
              }
          }
    
  • XML

    <androidx.cardview.widget.CardView
          android:id="@+id/forward"
          android:layout_width="550dp"
          android:layout_height="match_parent"
          app:layout_constraintStart_toEndOf="parent"
          app:layout_constraintEnd_toEndOf="parent"
          android:layout_marginVertical="50dp"
          android:foreground="?selectableItemBackgroundBorderless"
          app:cardCornerRadius="16px"
          app:cardElevation="0dp"
          android:backgroundTint="@android:color/transparent"/>
    

*Sorry for the bad gif quality

Sambhav Khandelwal
  • 3,585
  • 2
  • 7
  • 38

1 Answers1

0

If you convert it in kotlin you can use this

GestureDetector gestureDetector=new GestureDetector(getApplicationContext(),new GestureDetector.SimpleOnGestureListener(){
            @Override
            public boolean onDoubleTap(MotionEvent e) {
                // you can put your code here
                return super.onDoubleTap(e);
            }
        });
  • Thanks for you help @Shiv but I have already implemented the code for double click. The problem i am facing is that I was getting ripples for the first click also which i want to prevent. – Sambhav Khandelwal Nov 05 '22 at 14:37