答案 0 :(得分:1)
我也想实现这种功能,所以我自己写了它以“复制” YouTube的行为。几乎一样。您可以在此处找到包含示例应用程序的库:https://github.com/vkay94/DoubleTapPlayerView
说明是用README编写的,但是由于Stackoverflow的原理:
0)要求:
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