How to create youtube's double-tap gesture on Android?

三世轮回 提交于 2019-12-05 02:38:00

问题


I have application with exoplayer on Android. I have create youtube's double-tap gesture to jump 10 seconds forward or backward with animation! How create this semicircle with ripple effect on double tap?

Like this

How to do this?


回答1:


I've also wanted to implement such feature, so I wrote it myself to "copy" YouTube's behavior. It's almost the same. You can find the library here including a sample app: https://github.com/vkay94/DoubleTapPlayerView

The instructions are written in the README, but due to Stackoverflow principals:

0) Requirements:

  • Minimum SDK: 21 (could be lower, but I've not tested older versions yet)
  • ExoPlayer2 library (at least 2.10.4) since the replaced view is written above ExoPlayer's PlayerView

1) Include it to your gradle (it's hosted on jitpack.io so you've got to add it to your respositories):

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

dependencies {
    implementation 'com.github.vkay94:DoubleTapPlayerView:0.6.0'
}

2) Add the views inside your XML:

<FrameLayout
    ... >

    <!-- Replace ExoPlayer's PlayerView -->
    <com.github.vkay94.dtpv.DoubleTapPlayerView
        android:id="@+id/doubletapplayerview"
        app:player_layout_id="@layout/exo_simple_player_view"
        app:use_controller="true"
        ...
    />

    <!-- Other views e.g. ProgressBar etc  -->

    <!-- Add the overlay on top of PlayerView -->
    <com.github.vkay94.dtpv.YouTubeDoubleTap
        android:background="@color/dtp_overlay_dim"
        android:id="@+id/youTubeDoubleTap"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</FrameLayout>

3) Set it up inside your activity:

// Link the PlayerView to the overlay to pass increment to the Player (seekTo)
// Important: set the (Simple)ExoPlayer to the PlayerView before this call
youTubeDoubleTap
    .setPlayer(doubletapplayerview)
    .setForwardRewindIncrementMs(5000)

// Set YouTube overlay to the PlayerView and double tapping enabled (false by default)
doubletapplayerview
    .activateDoubleTap(true)
    .setDoubleTapDelay(500)
    .setDoubleTapListener(youTubeDoubleTap)
  //.setDoubleTapListener(this) => handle event directly within´the activity


来源:https://stackoverflow.com/questions/53173346/how-to-create-youtubes-double-tap-gesture-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!