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

View file

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

View file

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