@ -187,7 +187,7 @@ class VideoDetailContainerFragment : BaseLazyFragment(), OnBackPressedListener {
}
mViewModel . needToUpdateVideoInfo . observeNonNull ( this ) {
findFirstCompletely VisibleVideoViewByPosition ( ) ?. updateViewDetail ( it )
findVisibleVideoViewByPosition ( ) ?. updateViewDetail ( it )
}
}
@ -234,17 +234,14 @@ class VideoDetailContainerFragment : BaseLazyFragment(), OnBackPressedListener {
override fun onPageSelected ( position : Int , isBottom : Boolean ) {
smartRefreshLayout . isEnableLoadMore = isBottom
smartRefreshLayout . setNoMoreData ( isBottom )
if ( mScheduledPlayDisposable != null && ! mScheduledPlayDisposable !! . isDisposed ) {
mScheduledPlayDisposable !! . dispose ( )
mScheduledPlayDisposable = null
}
val isShowClick = SPUtils . getBoolean ( Constants . SP _SHOW _CLICK _GUIDE )
if ( !is ShowClick ) {
showClickGuide ( )
}
var visitCount = SPUtils . getInt ( Constants . SP _SHOW _DOUBLE _CLICK _GUIDE , 0 )
visitCount ++
if ( visitCount == 5 ) {
@ -254,64 +251,7 @@ class VideoDetailContainerFragment : BaseLazyFragment(), OnBackPressedListener {
SPUtils . setBoolean ( Constants . SP _SHOW _SLIDE _GUIDE , true )
SPUtils . setBoolean ( Constants . SP _SHOW _CLICK _GUIDE , true )
val pos = mViewPagerLayoutManager . findFirstCompletelyVisibleItemPosition ( )
val videoView = findFirstCompletelyVisibleVideoViewByPosition ( )
videoView ?. observeVolume ( requireActivity ( ) as AppCompatActivity )
if ( userVisibleHint ) {
//延时处理,快速滑动不播放视频
mScheduledPlayDisposable = rxTimer ( 1 ) {
if ( it >= 100 ) {
mScheduledPlayDisposable ?. dispose ( )
mScheduledPlayDisposable = null
if ( pos + 2 <= mAdapter . videoList . size - 1 ) { //预加载视频
ExoCacheManager . preload ( mAdapter . videoList [ pos + 1 ] . url )
ExoCacheManager . preload ( mAdapter . videoList [ pos + 2 ] . url )
Picasso . with ( context ) . load ( mAdapter . videoList [ pos + 1 ] . getThumb ( ) ) . fetch ( )
Picasso . with ( context ) . load ( mAdapter . videoList [ pos + 2 ] . getThumb ( ) ) . fetch ( )
} else if ( pos + 1 <= mAdapter . videoList . size - 1 ) {
ExoCacheManager . preload ( mAdapter . videoList [ pos + 1 ] . url )
Picasso . with ( context ) . load ( mAdapter . videoList [ pos + 1 ] . getThumb ( ) ) . fetch ( )
}
if ( mLastPosition != pos /*&& videoView?.isInPlayingState != true*/ ) {
ExoCacheManager . cancel ( mAdapter . videoList [ pos ] . url )
CustomManager . releaseAllVideos ( " detail_ ${mViewModel.uuid} " )
videoView ?. startButton ?. performClick ( )
mBaseHandler . postDelayed ( {
videoView ?. updateMuteStatus ( )
} , 500 )
}
mLastPosition = pos
mViewModel . addHistoryRecord ( mAdapter . videoList [ pos ] )
}
}
}
mViewModel . videoList . value ?. apply {
if ( pos > mViewModel . startPosition ) { //向上滑动
val videoId = if ( mLocation == VideoDetailContainerViewModel . Location . VIDEO_CHOICENESS . value || mLocation == VideoDetailContainerViewModel . Location . VIDEO_HOT . value ) {
mInitialVideoId
} else {
this [ size - 1 ] . id
}
if ( pos == size - 5 ) { //获取下面的视频
mViewModel . getVideoDetailList ( videoId , mLocation , isLoadNext = true )
}
//防止视频流分页获取的数据为空不会触发循环
if ( pos == size - 1 && mLocation == VideoDetailContainerViewModel . Location . VIDEO_CHOICENESS . value ) {
mViewModel . getVideoDetailList ( videoId , mLocation , isLoadNext = true )
}
setAdvertisement ( pos )
} else { //向下滑动
if ( pos == 4 ) { //获取上面的视频
mViewModel . getVideoDetailList ( this [ 0 ] . id , mLocation , isLoadNext = false )
}
}
mViewModel . startPosition = pos
mViewModel . currentDisplayingVideo = mAdapter . videoList [ mViewModel . startPosition ]
}
playVideo ( )
}
} )
@ -323,6 +263,66 @@ class VideoDetailContainerFragment : BaseLazyFragment(), OnBackPressedListener {
}
private fun playVideo ( ) {
// val pos = mViewPagerLayoutManager.findFirstCompletelyVisibleItemPosition()
val pos = mViewPagerLayoutManager . findLastCompletelyVisibleItemPosition ( )
val videoView = findVisibleVideoViewByPosition ( )
videoView ?. observeVolume ( requireActivity ( ) as AppCompatActivity )
if ( userVisibleHint ) {
//延时处理,快速滑动不播放视频
mScheduledPlayDisposable = rxTimer ( 1 ) {
if ( it >= 100 ) {
mScheduledPlayDisposable ?. dispose ( )
mScheduledPlayDisposable = null
if ( pos + 2 <= mAdapter . videoList . size - 1 ) { //预加载视频
ExoCacheManager . preload ( mAdapter . videoList [ pos + 1 ] . url )
ExoCacheManager . preload ( mAdapter . videoList [ pos + 2 ] . url )
Picasso . with ( context ) . load ( mAdapter . videoList [ pos + 1 ] . getThumb ( ) ) . fetch ( )
Picasso . with ( context ) . load ( mAdapter . videoList [ pos + 2 ] . getThumb ( ) ) . fetch ( )
} else if ( pos + 1 <= mAdapter . videoList . size - 1 ) {
ExoCacheManager . preload ( mAdapter . videoList [ pos + 1 ] . url )
Picasso . with ( context ) . load ( mAdapter . videoList [ pos + 1 ] . getThumb ( ) ) . fetch ( )
}
if ( mLastPosition != pos /*&& videoView?.isInPlayingState != true*/ ) {
ExoCacheManager . cancel ( mAdapter . videoList [ pos ] . url )
CustomManager . releaseAllVideos ( " detail_ ${mViewModel.uuid} " )
videoView ?. startButton ?. performClick ( )
mBaseHandler . postDelayed ( {
videoView ?. updateMuteStatus ( )
} , 500 )
}
mLastPosition = pos
mViewModel . addHistoryRecord ( mAdapter . videoList [ pos ] )
}
}
}
mViewModel . videoList . value ?. apply {
if ( pos > mViewModel . startPosition ) { //向上滑动
val videoId = if ( mLocation == VideoDetailContainerViewModel . Location . VIDEO_CHOICENESS . value || mLocation == VideoDetailContainerViewModel . Location . VIDEO_HOT . value ) {
mInitialVideoId
} else {
this [ size - 1 ] . id
}
if ( pos == size - 5 ) { //获取下面的视频
mViewModel . getVideoDetailList ( videoId , mLocation , isLoadNext = true )
}
//防止视频流分页获取的数据为空不会触发循环
if ( pos == size - 1 && mLocation == VideoDetailContainerViewModel . Location . VIDEO_CHOICENESS . value ) {
mViewModel . getVideoDetailList ( videoId , mLocation , isLoadNext = true )
}
setAdvertisement ( pos )
} else { //向下滑动
if ( pos == 4 ) { //获取上面的视频
mViewModel . getVideoDetailList ( this [ 0 ] . id , mLocation , isLoadNext = false )
}
}
mViewModel . startPosition = pos
mViewModel . currentDisplayingVideo = mAdapter . videoList [ mViewModel . startPosition ]
}
}
//显示滑动引导
private fun showSlideGuide ( ) {
mBaseHandler . postDelayed ( {
@ -354,7 +354,7 @@ class VideoDetailContainerFragment : BaseLazyFragment(), OnBackPressedListener {
mBaseHandler . postDelayed ( {
guideRl . visibility = View . VISIBLE
guideTitle . text = " 点击查看更多视频 "
val gameTitleY = findFirstCompletely VisibleVideoViewByPosition ( ) ?. getGameTitleY ( ) ?: 0
val gameTitleY = findVisibleVideoViewByPosition ( ) ?. getGameTitleY ( ) ?: 0
val layoutParams = slideGuideAnimation . layoutParams as RelativeLayout . LayoutParams
layoutParams . height = DisplayUtils . dip2px ( 68f )
@ -422,7 +422,7 @@ class VideoDetailContainerFragment : BaseLazyFragment(), OnBackPressedListener {
if ( pos < 0 ) return @setOnClickListener
val videoEntity = mAdapter . videoList [ pos ]
MtaHelper . onEvent ( " 视频详情 " , " 视频广告 " , " ${videoEntity.title} ( ${videoEntity.id} ) " )
findFirstCompletely VisibleVideoViewByPosition ( ) ?. uploadVideoStreamingPlaying ( " 点击广告 " )
findVisibleVideoViewByPosition ( ) ?. uploadVideoStreamingPlaying ( " 点击广告 " )
DirectUtils . directToLinkPage ( requireContext ( ) , LinkEntity ( link = link , type = linkType , community = linkCommunity ) , " " , " 视频详情 " )
}
@ -431,7 +431,7 @@ class VideoDetailContainerFragment : BaseLazyFragment(), OnBackPressedListener {
if ( pos < 0 ) return @setOnClickListener
val videoEntity = mAdapter . videoList [ pos ]
MtaHelper . onEvent ( " 视频详情 " , " 视频广告 " , " ${videoEntity.title} ( ${videoEntity.id} ) " )
findFirstCompletely VisibleVideoViewByPosition ( ) ?. uploadVideoStreamingPlaying ( " 点击广告 " )
findVisibleVideoViewByPosition ( ) ?. uploadVideoStreamingPlaying ( " 点击广告 " )
if ( linkType == " web " ) {
// 当前入口打开Web页面要显示分享按钮
@ -454,7 +454,7 @@ class VideoDetailContainerFragment : BaseLazyFragment(), OnBackPressedListener {
if ( finish ) {
marquee _ad . visibility = View . GONE
icon _ad . visibility = View . GONE
findFirstCompletely VisibleVideoViewByPosition ( ) ?. uploadVideoStreamingPlaying ( " 关闭广告 " )
findVisibleVideoViewByPosition ( ) ?. uploadVideoStreamingPlaying ( " 关闭广告 " )
}
}
}
@ -470,10 +470,10 @@ class VideoDetailContainerFragment : BaseLazyFragment(), OnBackPressedListener {
}
override fun onFragmentResume ( ) {
findFirstCompletely VisibleVideoViewByPosition ( ) ?. uploadVideoStreamingPlaying ( " 恢复页面 " )
findVisibleVideoViewByPosition ( ) ?. uploadVideoStreamingPlaying ( " 恢复页面 " )
DownloadManager . getInstance ( requireContext ( ) ) . addObserver ( dataWatcher )
if ( mViewModel . isPauseVideo ) {
val videoView = findFirstCompletely VisibleVideoViewByPosition ( )
val videoView = findVisibleVideoViewByPosition ( )
videoView ?. run {
if ( videoView . isInPlayingState ) {
videoView . onVideoResume ( false )
@ -500,7 +500,7 @@ class VideoDetailContainerFragment : BaseLazyFragment(), OnBackPressedListener {
mScheduledPlayDisposable = null
}
DownloadManager . getInstance ( requireContext ( ) ) . removeObserver ( dataWatcher )
val videoView = findFirstCompletely VisibleVideoViewByPosition ( )
val videoView = findVisibleVideoViewByPosition ( )
videoView ?. run {
videoView . uploadVideoStreamingPlaying ( " 暂停页面 " )
if ( mViewModel . isPauseVideo ) {
@ -521,7 +521,7 @@ class VideoDetailContainerFragment : BaseLazyFragment(), OnBackPressedListener {
}
override fun onDestroyView ( ) {
findFirstCompletely VisibleVideoViewByPosition ( ) ?. uploadVideoStreamingPlaying ( " 退出页面 " )
findVisibleVideoViewByPosition ( ) ?. uploadVideoStreamingPlaying ( " 退出页面 " )
CustomManager . releaseAllVideos ( " detail_ ${mViewModel.uuid} " )
mBaseHandler . postDelayed ( {
CustomManager . releaseAllVideos ( " detail_ ${mViewModel.uuid} " )
@ -533,8 +533,8 @@ class VideoDetailContainerFragment : BaseLazyFragment(), OnBackPressedListener {
ExoCacheManager . cancelAll ( )
}
private fun findFirstCompletely VisibleVideoViewByPosition ( ) : DetailPlayerView ? {
val pos = mViewPagerLayoutManager . findFir stCompletelyVisibleItemPosition ( )
private fun findVisibleVideoViewByPosition ( ) : DetailPlayerView ? {
val pos = mViewPagerLayoutManager . findLa stCompletelyVisibleItemPosition ( )
val holder = recyclerview ?. findViewHolderForAdapterPosition ( pos )
return holder ?. itemView as ? DetailPlayerView
@ -599,16 +599,16 @@ class VideoDetailContainerFragment : BaseLazyFragment(), OnBackPressedListener {
if ( UserManager . getInstance ( ) . isLoggedIn ) {
if ( video . me . isVideoFavorite ) {
MtaHelper . onEvent ( " 视频详情 " , " 更多-取消收藏 " , combinedTitleAndId )
findFirstCompletely VisibleVideoViewByPosition ( ) ?. uploadVideoStreamingPlaying ( " 更多-取消收藏 " )
findVisibleVideoViewByPosition ( ) ?. uploadVideoStreamingPlaying ( " 更多-取消收藏 " )
mViewModel . undoCollect ( )
} else {
MtaHelper . onEvent ( " 视频详情 " , " 更多-收藏 " , combinedTitleAndId )
findFirstCompletely VisibleVideoViewByPosition ( ) ?. uploadVideoStreamingPlaying ( " 更多-收藏 " )
findVisibleVideoViewByPosition ( ) ?. uploadVideoStreamingPlaying ( " 更多-收藏 " )
mViewModel . collect ( )
}
popupWindow . dismiss ( )
} else {
findFirstCompletely VisibleVideoViewByPosition ( ) ?. uploadVideoStreamingPlaying ( " 更多-收藏-跳转登录 " )
findVisibleVideoViewByPosition ( ) ?. uploadVideoStreamingPlaying ( " 更多-收藏-跳转登录 " )
CheckLoginUtils . checkLogin ( context , " (视频详情) " , { } )
}
}
@ -617,7 +617,7 @@ class VideoDetailContainerFragment : BaseLazyFragment(), OnBackPressedListener {
share ( )
popupWindow . dismiss ( )
MtaHelper . onEvent ( " 视频详情 " , " 更多-分享 " , combinedTitleAndId )
findFirstCompletely VisibleVideoViewByPosition ( ) ?. uploadVideoStreamingPlaying ( " 更多-分享 " )
findVisibleVideoViewByPosition ( ) ?. uploadVideoStreamingPlaying ( " 更多-分享 " )
}
}
@ -635,7 +635,7 @@ class VideoDetailContainerFragment : BaseLazyFragment(), OnBackPressedListener {
it . title ,
shareSummary ,
ShareUtils . ShareType . video ) {
findFirstCompletely VisibleVideoViewByPosition ( ) ?. uploadVideoStreamingPlaying ( " 更多-取消分享 " )
findVisibleVideoViewByPosition ( ) ?. uploadVideoStreamingPlaying ( " 更多-取消分享 " )
}
}
}
@ -648,9 +648,9 @@ class VideoDetailContainerFragment : BaseLazyFragment(), OnBackPressedListener {
if ( commentCount > 0 ) {
val videoEntity = mAdapter . videoList [ mViewModel . startPosition ]
videoEntity . commentCount = commentCount
findFirstCompletely VisibleVideoViewByPosition ( ) ?. updateViewDetail ( videoEntity )
findVisibleVideoViewByPosition ( ) ?. updateViewDetail ( videoEntity )
}
findFirstCompletely VisibleVideoViewByPosition ( ) ?. uploadVideoStreamingPlaying ( " 关闭评论弹窗 " )
findVisibleVideoViewByPosition ( ) ?. uploadVideoStreamingPlaying ( " 关闭评论弹窗 " )
}
}
}
@ -676,7 +676,7 @@ class VideoDetailContainerFragment : BaseLazyFragment(), OnBackPressedListener {
@Subscribe ( threadMode = ThreadMode . MAIN )
fun onEventMainThread ( status : EBReuse ) {
val videoView = findFirstCompletely VisibleVideoViewByPosition ( )
val videoView = findVisibleVideoViewByPosition ( )
//处理打开评论页面, 按手机Home键回到桌面, 还会听到视频的声音
if ( NewCommentFragment . COMMENT _PAUSE == status . type ) {
val haveMoreElementCount = AppManager . getInstance ( ) . haveMoreElementCount ( requireActivity ( ) )
@ -704,7 +704,7 @@ class VideoDetailContainerFragment : BaseLazyFragment(), OnBackPressedListener {
override fun onHandleBackPressed ( ) : Boolean {
if ( :: mAdapter . isInitialized ) {
return mAdapter . onBackPressed ( findFirstCompletely VisibleVideoViewByPosition ( ) )
return mAdapter . onBackPressed ( findVisibleVideoViewByPosition ( ) )
}
return false
}