新增 togglePlayingState2(isPlaying) 方法

This commit is contained in:
renhaoting 2026-01-13 18:57:16 +08:00
parent dae7ab4da9
commit a77f9709d8
1 changed files with 60 additions and 19 deletions

View File

@ -3,6 +3,8 @@ package com.gamedog.vididin.main.fragments.home.fragment
import android.graphics.Bitmap
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.Gravity
import android.view.LayoutInflater
import android.view.View
@ -35,12 +37,15 @@ class HomeItemFragment : AppViewsEmptyViewModelFragment<ViewBinding>() {
private var mPlayerView: YouTubePlayerView? = null
private var mPlayer: YouTubePlayer? = null
private var mVideoData: YoutubeVideo? = null
@Volatile
private var mIsPlaying: Boolean = false
private var mIsIntroExpand: Boolean = false
private var mCurPlayedSecond: Float = 0F
private var mTotalDuration: Float = 0F
private val mTickerTimer = TickerTimer()
private val mThumbHandler = Handler(Looper.getMainLooper())
override fun inflateViewBinding(
inflater: LayoutInflater,
@ -193,29 +198,14 @@ class HomeItemFragment : AppViewsEmptyViewModelFragment<ViewBinding>() {
}
}
private fun generateThumbAndSet() {
// capturePlayerView And Show as thumb
mPlayerView?.let {
mMaskBitmap?.recycle()
mMaskBitmap = null
mMaskBitmap = AndroidUtil.getThumbOfView(it)
mMaskBitmap?.let {
binding?.ivMask?.setImageBitmap(mMaskBitmap)
}
}
private fun togglePlayingState(isPlaying: Boolean) {
if (true) togglePlayingState1(isPlaying) else togglePlayingState2(isPlaying)
}
private fun togglePlayingState(isPlaying: Boolean) {
private fun togglePlayingState1(isPlaying: Boolean) {
if (mIsPlaying != isPlaying) {
mIsPlaying = isPlaying
if (!mIsPlaying) {
/*binding?.circlePb?.let {
it.postDelayed({
generateThumbAndSet()
}, 500)
}*/
} else {
if (mIsPlaying) {
binding?.circlePb?.isVisible = false
}
@ -234,6 +224,57 @@ class HomeItemFragment : AppViewsEmptyViewModelFragment<ViewBinding>() {
}
}
private fun switchState2Play() {
mThumbHandler.removeCallbacksAndMessages(null)
binding?.circlePb?.isVisible = false
binding?.ivMask?.isVisible = false
binding?.playerContainer?.isVisible = true
hidePlayIconAnim()
mTickerTimer.start()
}
private fun switchState2Pause() {
binding?.ivMask?.isVisible = true
binding?.playerContainer?.isVisible = false
showPlayIconAnim()
mTickerTimer.pause()
}
private fun togglePlayingState2(isPlaying: Boolean) {
if (mIsPlaying != isPlaying) {
mIsPlaying = isPlaying
if (isPlaying) {
switchState2Play()
} else {
mThumbHandler.removeCallbacksAndMessages(null)
binding?.ivMask?.setImageBitmap(null)
mThumbHandler.post {
if (mPlayerView != null) {
// hide others UI
AndroidUtil.getThumbOfView1(requireActivity().window, mPlayerView!!, { bitmap ->
if (!isPlaying) {
val preBitmap = mMaskBitmap
mMaskBitmap = bitmap
if (mMaskBitmap != null) {
binding?.ivMask?.setImageBitmap(mMaskBitmap)
preBitmap?.recycle()
}
binding?.playIcon?.post { switchState2Pause() }
}
})
} else {
binding?.playIcon?.post { switchState2Pause() }
}
}
}
sendPlayStopStatistic(mIsPlaying)
}
}
override fun onResume() {
super.onResume()
mPlayer?.play()