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

时间:2018-11-06 13:55:31

标签: android youtube android-drawable exoplayer

我在Android上有exoplayer的应用程序。我创建了youtube的点按两次手势,以使动画向前或向后跳10秒!如何在双击时创建具有波纹效果的半圆?

enter image description here

该怎么做?

1 个答案:

答案 0 :(得分:1)

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

说明是用README编写的,但是由于Stackoverflow的原理:

0)要求:

  • 最低SDK:21(可能更低,但我尚未测试旧版本)
  • ExoPlayer2库(至少为2.10.4),因为替换后的视图写在ExoPlayer的PlayerView上方

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

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

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

2)在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)在活动中进行设置:

// 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