如何在 Android 上创建 youtube 的双击手势?

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

我在 Android 上申请了 exoplayer。我已经创建了 youtube 的 双击手势 来用动画向前或向后跳 10 秒!如何在双击时创建具有波纹效果的半圆?

像这样

如何操作?

我也想实现这样的功能,所以我自己写了一个来“复制”YouTube的行为。几乎一样。您可以在此处找到包含示例应用程序的库:https://github.com/vkay94/DoubleTapPlayerView

说明写在自述文件中,但由于 Whosebug 原则:

0) 要求:

  • 最低 SDK:16(我无法测试低于 21 的版本)
  • ExoPlayer2库(至少2.11.7)因为替换的视图写在ExoPlayer的PlayerView上面)

1) 将它包含到您的 gradle(它托管在 jitpack.io 上,因此您必须将它添加到您的存储库):

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

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

2) 在 XML 中添加视图:

<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    
    <com.github.vkay94.dtpv.DoubleTapPlayerView
        android:id="@+id/playerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        
        app:dtpv_controller="@+id/youtube_overlay" />

    <com.github.vkay94.dtpv.youtube.YouTubeOverlay
        android:id="@+id/youtube_overlay"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="invisible"
        
        app:yt_playerView="@+id/playerView" />
</FrameLayout>

3) 在 activity:

中设置
youtube_overlay
    .performListener(object : YouTubeOverlay.PerformListener {
        override fun onAnimationStart() {
            // Do UI changes when circle scaling animation starts (e.g. hide controller views)
            youtube_overlay.visibility = View.VISIBLE
        }

        override fun onAnimationEnd() {
            // Do UI changes when circle scaling animation starts (e.g. show controller views)
            youtube_overlay.visibility = View.GONE
        }
    })
    // Uncomment this line if you haven't set yt_playerView in XML
    // .playerView(playerView)

// Uncomment this line if you haven't set dtpv_controller in XML 
// playerView.controller(youtube_overlay)

// Call this method whenever the player is released and recreated
youtube_overlay.player(simpleExoPlayer)