add skip forward/backward at panorama videos

This commit is contained in:
tibbi 2018-10-21 21:01:03 +02:00
parent 0cb212947c
commit 3ee3887754
3 changed files with 22 additions and 2 deletions

View file

@ -25,6 +25,7 @@ import com.simplemobiletools.gallery.extensions.hideSystemUI
import com.simplemobiletools.gallery.extensions.navigationBarHeight
import com.simplemobiletools.gallery.extensions.showSystemUI
import com.simplemobiletools.gallery.helpers.HIDE_PLAY_PAUSE_DELAY
import com.simplemobiletools.gallery.helpers.MIN_SKIP_LENGTH
import com.simplemobiletools.gallery.helpers.PATH
import com.simplemobiletools.gallery.helpers.PLAY_PAUSE_VISIBLE_ALPHA
import kotlinx.android.synthetic.main.activity_panorama_video.*
@ -113,6 +114,9 @@ open class PanoramaVideoActivity : SimpleActivity(), SeekBar.OnSeekBarChangeList
intent.removeExtra(PATH)
video_curr_time.setOnClickListener { skip(false) }
video_duration.setOnClickListener { skip(true) }
try {
val options = VrVideoView.Options()
options.inputType = VrVideoView.Options.TYPE_MONO
@ -209,6 +213,7 @@ open class PanoramaVideoActivity : SimpleActivity(), SeekBar.OnSeekBarChangeList
}
private fun playVideo() {
video_play_outline.setImageResource(R.drawable.ic_pause)
if (mCurrTime == mDuration) {
setVideoProgress(0)
mPlayOnReady = true
@ -216,7 +221,6 @@ open class PanoramaVideoActivity : SimpleActivity(), SeekBar.OnSeekBarChangeList
}
vr_video_view.playVideo()
video_play_outline.setImageResource(R.drawable.ic_pause)
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}
@ -286,6 +290,22 @@ open class PanoramaVideoActivity : SimpleActivity(), SeekBar.OnSeekBarChangeList
}
}
private fun skip(forward: Boolean) {
if (forward && mCurrTime == mDuration) {
return
}
val curr = vr_video_view.currentPosition
val twoPercents = Math.max((vr_video_view.duration / 50).toInt(), MIN_SKIP_LENGTH)
val newProgress = if (forward) curr + twoPercents else curr - twoPercents
val roundProgress = Math.round(newProgress / 1000f)
val limitedProgress = Math.max(Math.min(vr_video_view.duration.toInt(), roundProgress), 0)
setVideoProgress(limitedProgress)
if (!mIsPlaying) {
togglePlayPause()
}
}
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
if (fromUser) {
setVideoProgress(progress)

View file

@ -38,7 +38,6 @@ import java.io.File
class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, SeekBar.OnSeekBarChangeListener {
private val PROGRESS = "progress"
private val MIN_SKIP_LENGTH = 2000
private var mTextureView: TextureView? = null
private var mCurrTimeView: TextView? = null

View file

@ -88,6 +88,7 @@ const val DRAG_THRESHOLD = 8
const val MONTH_MILLISECONDS = MONTH_SECONDS * 1000L
const val HIDE_PLAY_PAUSE_DELAY = 500L
const val PLAY_PAUSE_VISIBLE_ALPHA = 0.8f
const val MIN_SKIP_LENGTH = 2000
const val DIRECTORY = "directory"
const val MEDIUM = "medium"