adding some video autoplay handling

This commit is contained in:
tibbi 2019-01-02 23:25:37 +01:00
parent 40f7321064
commit dd69bbea68
3 changed files with 21 additions and 14 deletions

View file

@ -12,10 +12,7 @@ import android.widget.RelativeLayout
import android.widget.SeekBar import android.widget.SeekBar
import com.google.vr.sdk.widgets.video.VrVideoEventListener import com.google.vr.sdk.widgets.video.VrVideoEventListener
import com.google.vr.sdk.widgets.video.VrVideoView import com.google.vr.sdk.widgets.video.VrVideoView
import com.simplemobiletools.commons.extensions.getFormattedDuration import com.simplemobiletools.commons.extensions.*
import com.simplemobiletools.commons.extensions.onGlobalLayout
import com.simplemobiletools.commons.extensions.showErrorToast
import com.simplemobiletools.commons.extensions.toast
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_STORAGE
import com.simplemobiletools.commons.helpers.isPiePlus import com.simplemobiletools.commons.helpers.isPiePlus
import com.simplemobiletools.gallery.pro.R import com.simplemobiletools.gallery.pro.R
@ -136,10 +133,14 @@ open class PanoramaVideoActivity : SimpleActivity(), SeekBar.OnSeekBarChangeList
setupTimer() setupTimer()
} }
if (mPlayOnReady) { if (mPlayOnReady || config.autoplayVideos) {
mPlayOnReady = false mPlayOnReady = false
playVideo() mIsPlaying = true
resumeVideo()
} else {
video_toggle_play_pause.setImageResource(R.drawable.ic_play_outline)
} }
video_toggle_play_pause.beVisible()
} }
override fun onCompletion() { override fun onCompletion() {
@ -190,13 +191,13 @@ open class PanoramaVideoActivity : SimpleActivity(), SeekBar.OnSeekBarChangeList
private fun togglePlayPause() { private fun togglePlayPause() {
mIsPlaying = !mIsPlaying mIsPlaying = !mIsPlaying
if (mIsPlaying) { if (mIsPlaying) {
playVideo() resumeVideo()
} else { } else {
pauseVideo() pauseVideo()
} }
} }
private fun playVideo() { private fun resumeVideo() {
video_toggle_play_pause.setImageResource(R.drawable.ic_pause_outline) video_toggle_play_pause.setImageResource(R.drawable.ic_pause_outline)
if (mCurrTime == mDuration) { if (mCurrTime == mDuration) {
setVideoProgress(0) setVideoProgress(0)
@ -319,7 +320,7 @@ open class PanoramaVideoActivity : SimpleActivity(), SeekBar.OnSeekBarChangeList
override fun onStopTrackingTouch(seekBar: SeekBar?) { override fun onStopTrackingTouch(seekBar: SeekBar?) {
mIsPlaying = true mIsPlaying = true
playVideo() resumeVideo()
mIsDragged = false mIsDragged = false
} }
} }

View file

@ -232,6 +232,7 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
private fun videoPrepared() { private fun videoPrepared() {
if (!mWasVideoStarted) { if (!mWasVideoStarted) {
video_toggle_play_pause.beVisible()
mDuration = (mExoPlayer!!.duration / 1000).toInt() mDuration = (mExoPlayer!!.duration / 1000).toInt()
video_seekbar.max = mDuration video_seekbar.max = mDuration
video_duration.text = mDuration.getFormattedDuration() video_duration.text = mDuration.getFormattedDuration()
@ -241,11 +242,15 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
setLastVideoSavedPosition() setLastVideoSavedPosition()
} }
playVideo() if (config.autoplayVideos) {
resumeVideo()
} else {
video_toggle_play_pause.setImageResource(R.drawable.ic_play_outline)
}
} }
} }
private fun playVideo() { private fun resumeVideo() {
video_toggle_play_pause.setImageResource(R.drawable.ic_pause_outline) video_toggle_play_pause.setImageResource(R.drawable.ic_pause_outline)
if (mExoPlayer == null) { if (mExoPlayer == null) {
return return
@ -279,7 +284,7 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
private fun togglePlayPause() { private fun togglePlayPause() {
mIsPlaying = !mIsPlaying mIsPlaying = !mIsPlaying
if (mIsPlaying) { if (mIsPlaying) {
playVideo() resumeVideo()
} else { } else {
pauseVideo() pauseVideo()
} }
@ -305,7 +310,7 @@ open class VideoPlayerActivity : SimpleActivity(), SeekBar.OnSeekBarChangeListen
clearLastVideoSavedProgress() clearLastVideoSavedProgress()
mCurrTime = (mExoPlayer!!.duration / 1000).toInt() mCurrTime = (mExoPlayer!!.duration / 1000).toInt()
if (config.loopVideos) { if (config.loopVideos) {
playVideo() resumeVideo()
} else { } else {
video_seekbar.progress = video_seekbar.max video_seekbar.progress = video_seekbar.max
video_curr_time.text = mDuration.getFormattedDuration() video_curr_time.text = mDuration.getFormattedDuration()

View file

@ -16,7 +16,8 @@
android:layout_marginTop="@dimen/activity_margin" android:layout_marginTop="@dimen/activity_margin"
android:background="?attr/selectableItemBackgroundBorderless" android:background="?attr/selectableItemBackgroundBorderless"
android:padding="@dimen/small_margin" android:padding="@dimen/small_margin"
android:src="@drawable/ic_pause_outline"/> android:src="@drawable/ic_pause_outline"
android:visibility="invisible"/>
<TextView <TextView
android:id="@+id/video_curr_time" android:id="@+id/video_curr_time"