hide the Pause button over the video under some circumstances
This commit is contained in:
parent
1038ee33d2
commit
5adc4fe1bd
1 changed files with 23 additions and 7 deletions
|
@ -38,16 +38,18 @@ import java.io.File
|
||||||
class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, SeekBar.OnSeekBarChangeListener {
|
class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, SeekBar.OnSeekBarChangeListener {
|
||||||
private val PROGRESS = "progress"
|
private val PROGRESS = "progress"
|
||||||
private val MIN_SKIP_LENGTH = 2000
|
private val MIN_SKIP_LENGTH = 2000
|
||||||
|
private val HIDE_PAUSE_DELAY = 2000L
|
||||||
private val PLAY_PAUSE_VISIBLE_ALPHA = 0.8f
|
private val PLAY_PAUSE_VISIBLE_ALPHA = 0.8f
|
||||||
|
|
||||||
private var mTextureView: TextureView? = null
|
private var mTextureView: TextureView? = null
|
||||||
private var mCurrTimeView: TextView? = null
|
private var mCurrTimeView: TextView? = null
|
||||||
private var mTimerHandler: Handler? = null
|
|
||||||
private var mSeekBar: SeekBar? = null
|
private var mSeekBar: SeekBar? = null
|
||||||
private var mTimeHolder: View? = null
|
private var mTimeHolder: View? = null
|
||||||
private var mView: View? = null
|
private var mView: View? = null
|
||||||
private var mExoPlayer: SimpleExoPlayer? = null
|
private var mExoPlayer: SimpleExoPlayer? = null
|
||||||
private var mVideoSize = Point(0, 0)
|
private var mVideoSize = Point(0, 0)
|
||||||
|
private var mTimerHandler = Handler()
|
||||||
|
private var mHidePauseHandler = Handler()
|
||||||
|
|
||||||
private var mIsPlaying = false
|
private var mIsPlaying = false
|
||||||
private var mIsDragged = false
|
private var mIsDragged = false
|
||||||
|
@ -314,7 +316,6 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
private fun setupTimeHolder() {
|
private fun setupTimeHolder() {
|
||||||
mSeekBar!!.max = mDuration
|
mSeekBar!!.max = mDuration
|
||||||
mView!!.video_duration.text = mDuration.getFormattedDuration()
|
mView!!.video_duration.text = mDuration.getFormattedDuration()
|
||||||
mTimerHandler = Handler()
|
|
||||||
setupTimer()
|
setupTimer()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,7 +328,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
mCurrTimeView!!.text = mCurrTime.getFormattedDuration()
|
mCurrTimeView!!.text = mCurrTime.getFormattedDuration()
|
||||||
}
|
}
|
||||||
|
|
||||||
mTimerHandler!!.postDelayed(this, 1000)
|
mTimerHandler.postDelayed(this, 1000)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -362,6 +363,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
return
|
return
|
||||||
|
|
||||||
mIsPlaying = !mIsPlaying
|
mIsPlaying = !mIsPlaying
|
||||||
|
mHidePauseHandler.removeCallbacksAndMessages(null)
|
||||||
if (mIsPlaying) {
|
if (mIsPlaying) {
|
||||||
playVideo()
|
playVideo()
|
||||||
} else {
|
} else {
|
||||||
|
@ -382,6 +384,9 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
mExoPlayer?.playWhenReady = true
|
mExoPlayer?.playWhenReady = true
|
||||||
mView!!.video_play_outline.setImageDrawable(resources.getDrawable(R.drawable.img_pause_outline_big))
|
mView!!.video_play_outline.setImageDrawable(resources.getDrawable(R.drawable.img_pause_outline_big))
|
||||||
activity!!.window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
activity!!.window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||||
|
mHidePauseHandler.postDelayed({
|
||||||
|
mView!!.video_play_outline.animate().alpha(0f).start()
|
||||||
|
}, HIDE_PAUSE_DELAY)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun pauseVideo() {
|
private fun pauseVideo() {
|
||||||
|
@ -393,8 +398,11 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
if (!videoEnded()) {
|
if (!videoEnded()) {
|
||||||
mExoPlayer?.playWhenReady = false
|
mExoPlayer?.playWhenReady = false
|
||||||
}
|
}
|
||||||
|
|
||||||
mView?.video_play_outline?.setImageDrawable(resources.getDrawable(R.drawable.img_play_outline_big))
|
mView?.video_play_outline?.setImageDrawable(resources.getDrawable(R.drawable.img_play_outline_big))
|
||||||
|
mView!!.video_play_outline.alpha = PLAY_PAUSE_VISIBLE_ALPHA
|
||||||
activity!!.window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
activity!!.window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun videoEnded() = mExoPlayer!!.currentPosition >= mExoPlayer!!.duration
|
private fun videoEnded() = mExoPlayer!!.currentPosition >= mExoPlayer!!.duration
|
||||||
|
@ -435,13 +443,14 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
private fun cleanup() {
|
private fun cleanup() {
|
||||||
pauseVideo()
|
pauseVideo()
|
||||||
mCurrTimeView?.text = 0.getFormattedDuration()
|
mCurrTimeView?.text = 0.getFormattedDuration()
|
||||||
releaseMediaPlayer()
|
releaseExoPlayer()
|
||||||
mSeekBar?.progress = 0
|
mSeekBar?.progress = 0
|
||||||
mTimerHandler?.removeCallbacksAndMessages(null)
|
mTimerHandler.removeCallbacksAndMessages(null)
|
||||||
|
mHidePauseHandler.removeCallbacksAndMessages(null)
|
||||||
mTextureView = null
|
mTextureView = null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun releaseMediaPlayer() {
|
private fun releaseExoPlayer() {
|
||||||
mExoPlayer?.stop()
|
mExoPlayer?.stop()
|
||||||
mExoPlayer?.release()
|
mExoPlayer?.release()
|
||||||
mExoPlayer = null
|
mExoPlayer = null
|
||||||
|
@ -454,7 +463,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSurfaceTextureDestroyed(surface: SurfaceTexture?): Boolean {
|
override fun onSurfaceTextureDestroyed(surface: SurfaceTexture?): Boolean {
|
||||||
releaseMediaPlayer()
|
releaseExoPlayer()
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -571,6 +580,13 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
||||||
}
|
}
|
||||||
|
|
||||||
mView!!.video_play_outline.animate().alpha(if (isFullscreen) 0f else PLAY_PAUSE_VISIBLE_ALPHA).start()
|
mView!!.video_play_outline.animate().alpha(if (isFullscreen) 0f else PLAY_PAUSE_VISIBLE_ALPHA).start()
|
||||||
|
if (!isFullscreen) {
|
||||||
|
mHidePauseHandler.postDelayed({
|
||||||
|
mView!!.video_play_outline.animate().alpha(0f).start()
|
||||||
|
}, HIDE_PAUSE_DELAY)
|
||||||
|
} else {
|
||||||
|
mHidePauseHandler.removeCallbacksAndMessages(null)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getExtendedDetailsY(height: Int): Float {
|
private fun getExtendedDetailsY(height: Int): Float {
|
||||||
|
|
Loading…
Reference in a new issue