Skip to content

Commit

Permalink
Fix double tap to play/pause
Browse files Browse the repository at this point in the history
  • Loading branch information
moneytoo committed Mar 16, 2021
1 parent f414028 commit e92c9fd
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions app/src/main/java/com/brouken/player/dtpv/youtube/YouTubeOverlay.kt
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,24 @@ class YouTubeOverlay(context: Context?, private val attrs: AttributeSet?) :
val secondsTextView: TextView
get() = seconds_view.textView

override fun onDoubleTapStarted(posX: Float, posY: Float) {

if (player?.currentPosition != null && playerView?.width != null) {
if (posX >= playerView?.width!! * 0.35 && posX <= playerView?.width!! * 0.65) {
if (player?.isPlaying!!) {
player?.pause()
} else {
player?.play()
if (playerView?.isControllerFullyVisible!!)
playerView?.hideController()
}
return
}
}

super.onDoubleTapStarted(posX, posY)
}

override fun onDoubleTapProgressUp(posX: Float, posY: Float) {

// Check first whether forwarding/rewinding is "valid"
Expand All @@ -320,16 +338,6 @@ class YouTubeOverlay(context: Context?, private val attrs: AttributeSet?) :
return
}

if (posX >= playerView?.width!! * 0.35 && posX <= playerView?.width!! * 0.65) {
if (player?.isPlaying!!) {
player?.pause()
} else {
player?.play()
if (playerView?.isControllerFullyVisible!!)
playerView?.hideController()
}
}

// YouTube behavior: show overlay on MOTION_UP
// But check whether the first double tap is in invalid area
if (this.visibility != View.VISIBLE) {
Expand Down

0 comments on commit e92c9fd

Please sign in to comment.