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

问题描述 投票:0回答:2

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

像这样

enter image description here

如何做到这一点?

android youtube android-drawable exoplayer
2个回答
1
投票

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

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

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

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)

0
投票

这个问题已经由 @vkay 回答了,尽管他是为 Exoplayer 2.x.x 创建的,如果你想在

Media3-Exoplayer
中实现,你可以轻松做到,只需检查他的 GitHub 存储库复制资源文件和 Java 和 Kotlin 文件即可如果您在 Java 项目中使用它,将会在
DoubletapPlayerView
模块中找到它 那么你必须在
Build.Gradle
中编写两行代码 添加
Dependency of kotlin-core
库和
Kotlin option

之后,您必须将 Exoplayer 2.x.x 导入更改为

Media3 exoplayer

  android {
       buildTypes {
            release {
                isMinifyEnable = false;
                proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
            }
        }
        compileOptions {
            sourceCompatibility JavaVersion.VERSION_1_8
            targetCompatibility JavaVersion.VERSION_1_8
        }

// add this line in your project
        kotlinOptions {
            jvmTarget = JavaVersion.VERSION_1_8
        }
    
  dependencies {
// also add this in your project
        implementation 'androidx.core:core-ktx:1.12.0'
    }
© www.soinside.com 2019 - 2024. All rights reserved.