新增 togglePlayingState2(isPlaying) 方法
This commit is contained in:
parent
dae7ab4da9
commit
a77f9709d8
|
|
@ -3,6 +3,8 @@ package com.gamedog.vididin.main.fragments.home.fragment
|
||||||
|
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
import android.view.Gravity
|
import android.view.Gravity
|
||||||
import android.view.LayoutInflater
|
import android.view.LayoutInflater
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
|
@ -35,12 +37,15 @@ class HomeItemFragment : AppViewsEmptyViewModelFragment<ViewBinding>() {
|
||||||
private var mPlayerView: YouTubePlayerView? = null
|
private var mPlayerView: YouTubePlayerView? = null
|
||||||
private var mPlayer: YouTubePlayer? = null
|
private var mPlayer: YouTubePlayer? = null
|
||||||
private var mVideoData: YoutubeVideo? = null
|
private var mVideoData: YoutubeVideo? = null
|
||||||
|
@Volatile
|
||||||
private var mIsPlaying: Boolean = false
|
private var mIsPlaying: Boolean = false
|
||||||
private var mIsIntroExpand: Boolean = false
|
private var mIsIntroExpand: Boolean = false
|
||||||
private var mCurPlayedSecond: Float = 0F
|
private var mCurPlayedSecond: Float = 0F
|
||||||
private var mTotalDuration: Float = 0F
|
private var mTotalDuration: Float = 0F
|
||||||
private val mTickerTimer = TickerTimer()
|
private val mTickerTimer = TickerTimer()
|
||||||
|
|
||||||
|
private val mThumbHandler = Handler(Looper.getMainLooper())
|
||||||
|
|
||||||
|
|
||||||
override fun inflateViewBinding(
|
override fun inflateViewBinding(
|
||||||
inflater: LayoutInflater,
|
inflater: LayoutInflater,
|
||||||
|
|
@ -193,29 +198,14 @@ class HomeItemFragment : AppViewsEmptyViewModelFragment<ViewBinding>() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun togglePlayingState(isPlaying: Boolean) {
|
||||||
private fun generateThumbAndSet() {
|
if (true) togglePlayingState1(isPlaying) else togglePlayingState2(isPlaying)
|
||||||
// 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) {
|
private fun togglePlayingState1(isPlaying: Boolean) {
|
||||||
if (mIsPlaying != isPlaying) {
|
if (mIsPlaying != isPlaying) {
|
||||||
mIsPlaying = isPlaying
|
mIsPlaying = isPlaying
|
||||||
if (!mIsPlaying) {
|
if (mIsPlaying) {
|
||||||
/*binding?.circlePb?.let {
|
|
||||||
it.postDelayed({
|
|
||||||
generateThumbAndSet()
|
|
||||||
}, 500)
|
|
||||||
}*/
|
|
||||||
} else {
|
|
||||||
binding?.circlePb?.isVisible = false
|
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() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
mPlayer?.play()
|
mPlayer?.play()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue