refactor: 将明君优化的宣传视频播放优化复制到公共module;
This commit is contained in:
@@ -21,6 +21,7 @@ import com.mogo.eagle.core.utilcode.mogo.logger.scene.SceneConstant
|
||||
import com.mogo.eagle.core.utilcode.util.CountDownTimer
|
||||
import com.mogo.eagle.core.utilcode.util.FileUtils
|
||||
import com.mogo.eagle.core.utilcode.util.ThreadUtils
|
||||
import com.mogo.eagle.core.utilcode.util.UiThreadHandler
|
||||
import com.mogo.och.common.module.R
|
||||
import com.mogo.och.common.module.wigets.video.ImageVideoRotationView
|
||||
import com.shuyu.gsyvideoplayer.builder.GSYVideoOptionBuilder
|
||||
@@ -29,7 +30,6 @@ import com.shuyu.gsyvideoplayer.utils.Debuger
|
||||
import com.shuyu.gsyvideoplayer.utils.GSYVideoType
|
||||
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer
|
||||
import java.io.File
|
||||
import java.lang.Exception
|
||||
|
||||
class AdvanceVideoView @JvmOverloads constructor(
|
||||
context: Context, attrs: AttributeSet? = null
|
||||
@@ -92,8 +92,20 @@ class AdvanceVideoView @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
private fun loadCacheImg() {
|
||||
videoViewPlayer?.thumbImageView = cacheImage
|
||||
cacheImage?.setImageResource(R.drawable.video_holder)
|
||||
setCacheImageViewVisible()
|
||||
Logger.d(ImageVideoRotationView.TAG, "setVideoPath")
|
||||
cacheImage?.let {
|
||||
Glide.with(context).load(cacheImageUrl)
|
||||
.apply(
|
||||
RequestOptions().placeholder(R.drawable.video_holder)
|
||||
.error(R.drawable.video_holder)
|
||||
.fallback(R.drawable.video_holder)
|
||||
.centerCrop()
|
||||
)
|
||||
.into(it)
|
||||
}
|
||||
}
|
||||
|
||||
fun clearLocalErrorVideo() {
|
||||
@@ -106,13 +118,11 @@ class AdvanceVideoView @JvmOverloads constructor(
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
fun setCacheImageViewVisible() {
|
||||
videoViewPlayer?.thumbImageView = cacheImage
|
||||
videoViewPlayer?.setCacheImageViewVisible()
|
||||
}
|
||||
|
||||
fun setCacheImageViewGone() {
|
||||
videoViewPlayer?.setCacheImageViewGone()
|
||||
videoViewPlayer?.clearThumbImageView()
|
||||
}
|
||||
|
||||
fun setVideo(onCompletionListener: GSYSampleCallBack) {
|
||||
@@ -187,6 +197,10 @@ class AdvanceVideoView @JvmOverloads constructor(
|
||||
|
||||
override fun onPause(url: String?, threadBean: ThreadBean?) {
|
||||
Logger.d(ImageVideoRotationView.TAG, "download-onPause")
|
||||
// UiThreadHandler.postDelayed(Runnable {
|
||||
// startDownLoadVideo()
|
||||
// },DOWNLOAD_DELAY)
|
||||
// todo 测试下网络断掉是否会走onpause,且网络回复也不会继续下载
|
||||
}
|
||||
|
||||
override fun onProgress(url: String?, length: Int) {
|
||||
@@ -194,10 +208,24 @@ class AdvanceVideoView @JvmOverloads constructor(
|
||||
}
|
||||
|
||||
override fun onFinished(url: String?, threadBean: ThreadBean?) {
|
||||
Logger.d(ImageVideoRotationView.TAG, "download-onFinished")
|
||||
//下载完成
|
||||
ThreadUtils.runOnUiThread {
|
||||
startPlay()
|
||||
Logger.d(ImageVideoRotationView.TAG, "download-onFinished = $url")
|
||||
if (url.equals(fileNetPath)) { //发现下载工具在断网又连网后,已完成的任务又都下载,跳转播放出现问题
|
||||
//下载完成
|
||||
ThreadUtils.runOnUiThread {
|
||||
startPlay()
|
||||
}
|
||||
} else {//如果当前文件不存在再次去下载当前的
|
||||
Logger.d(
|
||||
ImageVideoRotationView.TAG, "download-onFinished = not current" +
|
||||
",currentUrl = $fileNetPath "
|
||||
)
|
||||
if (FileUtils.isFileExists(mVideoDirPath + downloadVideoName)) {
|
||||
Logger.d(ImageVideoRotationView.TAG, "have download startPlay")
|
||||
startPlay()
|
||||
return
|
||||
} else {
|
||||
startDownLoadVideo()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -230,10 +258,12 @@ class AdvancePagerAdapter(context: Context, viewPager: ViewPager) : PagerAdapter
|
||||
ViewPager.OnPageChangeListener {
|
||||
private val mContext: Context = context
|
||||
private val mViewPager: ViewPager = viewPager
|
||||
|
||||
private var dataList = mutableListOf<RotationItem>()
|
||||
private var viewList = mutableListOf<View>()
|
||||
|
||||
private var lastPosition = -1
|
||||
|
||||
private var current = 0
|
||||
private val time = 5000
|
||||
private var pause = false
|
||||
@@ -242,9 +272,7 @@ class AdvancePagerAdapter(context: Context, viewPager: ViewPager) : PagerAdapter
|
||||
fun setData(list: MutableList<RotationItem>) {
|
||||
if (list.isEmpty()) return
|
||||
dataList.addAll(list)
|
||||
|
||||
viewList.clear()
|
||||
|
||||
list.forEach {
|
||||
addView(it)
|
||||
}
|
||||
@@ -258,7 +286,6 @@ class AdvancePagerAdapter(context: Context, viewPager: ViewPager) : PagerAdapter
|
||||
Logger.d(ImageVideoRotationView.TAG, "第一个是视频")
|
||||
val video = viewList[mViewPager.currentItem] as AdvanceVideoView
|
||||
video.setVideo(gsySampleCallBack)
|
||||
|
||||
} else if (viewList[mViewPager.currentItem] is AdvanceImageView) {
|
||||
Logger.d(ImageVideoRotationView.TAG, "startTimer()_1")
|
||||
current = 0//换页重新计算时间
|
||||
@@ -331,7 +358,6 @@ class AdvancePagerAdapter(context: Context, viewPager: ViewPager) : PagerAdapter
|
||||
ImageVideoRotationView.TAG,
|
||||
"state = $state currentItem = $currentItem lastPosition = $lastPosition"
|
||||
)
|
||||
|
||||
if (viewList.size > 1) { //多于1,才会循环跳转
|
||||
if (viewList[mViewPager.currentItem] is AdvanceVideoView) {
|
||||
val videoView = (viewList[mViewPager.currentItem] as AdvanceVideoView)
|
||||
@@ -348,11 +374,14 @@ class AdvancePagerAdapter(context: Context, viewPager: ViewPager) : PagerAdapter
|
||||
}
|
||||
|
||||
private var gsySampleCallBack = object : GSYSampleCallBack() {
|
||||
|
||||
override fun onPrepared(url: String?, vararg objects: Any?) {
|
||||
Logger.d(ImageVideoRotationView.TAG, "onPrepared")
|
||||
if (viewList[mViewPager.currentItem] is AdvanceVideoView) {
|
||||
val videoView = (viewList[mViewPager.currentItem] as AdvanceVideoView)
|
||||
videoView.setCacheImageViewGone()
|
||||
UiThreadHandler.postDelayed(Runnable {
|
||||
videoView.setCacheImageViewGone()
|
||||
}, 1500)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -440,9 +469,15 @@ class AdvanceImageView @JvmOverloads constructor(
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
fun setImagePath(path: String) {
|
||||
imageView?.setImageResource(R.drawable.video_holder)
|
||||
imageView?.let {
|
||||
Glide.with(context).load(path)
|
||||
.apply(RequestOptions().placeholder(R.drawable.video_holder).centerCrop())
|
||||
.apply(
|
||||
RequestOptions().placeholder(R.drawable.video_holder)
|
||||
.error(R.drawable.video_holder)
|
||||
.fallback(R.drawable.video_holder)
|
||||
.centerCrop()
|
||||
)
|
||||
.into(it)
|
||||
}
|
||||
}
|
||||
@@ -495,14 +530,11 @@ class AdvanceGSYVideoPlayer : StandardGSYVideoPlayer {
|
||||
setViewShowState(mBottomProgressBar, INVISIBLE)
|
||||
setViewShowState(mBackButton, INVISIBLE)
|
||||
setViewShowState(mStartButton, INVISIBLE)
|
||||
|
||||
setViewShowState(mTopContainer, INVISIBLE)
|
||||
|
||||
setViewShowState(mLoadingProgressBar, INVISIBLE)
|
||||
setViewShowState(
|
||||
mLockScreen, INVISIBLE
|
||||
)
|
||||
|
||||
setIsTouchWiget(false)
|
||||
isFocusableInTouchMode = false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user