播放按钮动画
This commit is contained in:
parent
5ce3547a71
commit
dbc6799b0a
|
|
@ -3,7 +3,12 @@ package com.gamedog.vididin.main.fragments.home.fragment
|
|||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.view.animation.AlphaAnimation
|
||||
import android.view.animation.Animation
|
||||
import android.view.animation.AnimationSet
|
||||
import android.view.animation.ScaleAnimation
|
||||
import androidx.annotation.NonNull
|
||||
import com.ama.core.architecture.appBase.AppViewsEmptyViewModelFragment
|
||||
import com.ama.core.common.widget.PopMenuIconView
|
||||
|
|
@ -23,6 +28,7 @@ class HomeItemFragment : AppViewsEmptyViewModelFragment<ViewBinding>() {
|
|||
private var mIsStared = false
|
||||
private var mPlayer: YouTubePlayer? = null
|
||||
private var mVideoData: YoutubeVideo? = null
|
||||
private var mIsPlaying: Boolean = false
|
||||
|
||||
|
||||
override fun inflateViewBinding(
|
||||
|
|
@ -32,13 +38,12 @@ class HomeItemFragment : AppViewsEmptyViewModelFragment<ViewBinding>() {
|
|||
|
||||
|
||||
override fun ViewBinding.initViews() {
|
||||
tvPlay.setOnClickListener {
|
||||
mPlayer?.play()
|
||||
maskView.setOnClickListener {
|
||||
if (mIsPlaying) mPlayer?.pause() else mPlayer?.play()
|
||||
}
|
||||
tvPause.setOnClickListener {
|
||||
mPlayer?.pause()
|
||||
//mPlayer.seekTo()
|
||||
mPlayer?.setPlaybackRate(PlayerConstants.PlaybackRate.RATE_2)
|
||||
|
||||
playIcon.setOnClickListener {
|
||||
if (mIsPlaying) mPlayer?.pause() else mPlayer?.play()
|
||||
}
|
||||
|
||||
tvVideoFrom.text = "@From-" + arguments?.getLong(KEY_ID).toString()
|
||||
|
|
@ -172,7 +177,6 @@ class HomeItemFragment : AppViewsEmptyViewModelFragment<ViewBinding>() {
|
|||
|
||||
val playerView = mPlayerView
|
||||
playerView!!.addYouTubePlayerListener(object : AbstractYouTubePlayerListener() {
|
||||
|
||||
override fun onReady(@NonNull youTubePlayer: YouTubePlayer) {
|
||||
mPlayer = youTubePlayer
|
||||
|
||||
|
|
@ -193,19 +197,100 @@ class HomeItemFragment : AppViewsEmptyViewModelFragment<ViewBinding>() {
|
|||
state: PlayerConstants.PlayerState
|
||||
) {
|
||||
when (state) {
|
||||
PlayerConstants.PlayerState.UNKNOWN -> { }
|
||||
PlayerConstants.PlayerState.UNSTARTED -> { }
|
||||
PlayerConstants.PlayerState.ENDED -> { }
|
||||
PlayerConstants.PlayerState.PLAYING -> { }
|
||||
PlayerConstants.PlayerState.PAUSED -> { }
|
||||
PlayerConstants.PlayerState.BUFFERING -> { }
|
||||
PlayerConstants.PlayerState.VIDEO_CUED -> { }
|
||||
PlayerConstants.PlayerState.PLAYING -> {
|
||||
mIsPlaying = true
|
||||
hidePlayIconAnim()
|
||||
}
|
||||
PlayerConstants.PlayerState.PAUSED -> {
|
||||
mIsPlaying = false
|
||||
showPlayIconAnim()
|
||||
}
|
||||
PlayerConstants.PlayerState.UNKNOWN -> {
|
||||
mIsPlaying = false
|
||||
}
|
||||
PlayerConstants.PlayerState.UNSTARTED -> {
|
||||
mIsPlaying = false
|
||||
}
|
||||
PlayerConstants.PlayerState.ENDED -> {
|
||||
mIsPlaying = false
|
||||
showPlayIconAnim()
|
||||
}
|
||||
PlayerConstants.PlayerState.BUFFERING -> {
|
||||
mIsPlaying = false
|
||||
}
|
||||
PlayerConstants.PlayerState.VIDEO_CUED -> {
|
||||
mIsPlaying = false
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
private fun hidePlayIconAnim() {
|
||||
with (binding?.playIcon!!) {
|
||||
val animationSet = AnimationSet(true)
|
||||
animationSet.duration = 250
|
||||
val alphaAnimation = AlphaAnimation(1.0f, 0.5f)
|
||||
val scaleAnimation = ScaleAnimation(
|
||||
1.0f, 0.5f,
|
||||
1.0f, 0.5f,
|
||||
Animation.RELATIVE_TO_SELF, 0.5f,
|
||||
Animation.RELATIVE_TO_SELF, 0.5f
|
||||
)
|
||||
animationSet.addAnimation(alphaAnimation)
|
||||
animationSet.addAnimation(scaleAnimation)
|
||||
|
||||
animationSet.setAnimationListener(object : Animation.AnimationListener {
|
||||
override fun onAnimationStart(animation: Animation) {
|
||||
}
|
||||
|
||||
override fun onAnimationEnd(animation: Animation) {
|
||||
visibility = View.GONE
|
||||
}
|
||||
|
||||
override fun onAnimationRepeat(animation: Animation) {
|
||||
}
|
||||
})
|
||||
|
||||
startAnimation(animationSet)
|
||||
}
|
||||
}
|
||||
|
||||
private fun showPlayIconAnim() {
|
||||
with (binding?.playIcon!!) {
|
||||
visibility = View.VISIBLE
|
||||
|
||||
val animationSet = AnimationSet(true)
|
||||
animationSet.duration = 250
|
||||
val alphaAnimation = AlphaAnimation(0.5f, 1.0f)
|
||||
val scaleAnimation = ScaleAnimation(
|
||||
0.5f, 1.0f,
|
||||
0.5f, 1.0f,
|
||||
Animation.RELATIVE_TO_SELF, 0.5f,
|
||||
Animation.RELATIVE_TO_SELF, 0.5f
|
||||
)
|
||||
animationSet.addAnimation(alphaAnimation)
|
||||
animationSet.addAnimation(scaleAnimation)
|
||||
|
||||
animationSet.setAnimationListener(object : Animation.AnimationListener {
|
||||
override fun onAnimationStart(animation: Animation) {
|
||||
}
|
||||
|
||||
override fun onAnimationEnd(animation: Animation) {
|
||||
|
||||
}
|
||||
|
||||
override fun onAnimationRepeat(animation: Animation) {
|
||||
}
|
||||
})
|
||||
|
||||
startAnimation(animationSet)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
companion object {
|
||||
private const val KEY_ID = "id"
|
||||
|
|
|
|||
|
|
@ -21,12 +21,21 @@
|
|||
android:id="@+id/mask_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="#33FF0000"
|
||||
android:clickable="true"
|
||||
/>
|
||||
|
||||
|
||||
<LinearLayout
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/play_icon"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="100dp"
|
||||
android:padding="20dp"
|
||||
android:src="@mipmap/icon_play"
|
||||
android:layout_gravity="center"/>
|
||||
|
||||
|
||||
|
||||
<!--<LinearLayout
|
||||
android:id="@+id/controls_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
@ -54,7 +63,7 @@
|
|||
android:text="pause"
|
||||
android:layout_marginLeft="20dp"
|
||||
/>
|
||||
</LinearLayout>
|
||||
</LinearLayout>-->
|
||||
|
||||
|
||||
<LinearLayout
|
||||
|
|
|
|||
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
Loading…
Reference in New Issue