implement vr video play/pause
This commit is contained in:
parent
5d419ea88a
commit
64180c0af1
|
@ -4,6 +4,7 @@ import android.content.res.Configuration
|
|||
import android.graphics.Color
|
||||
import android.net.Uri
|
||||
import android.os.Bundle
|
||||
import android.os.Handler
|
||||
import android.view.View
|
||||
import android.view.Window
|
||||
import android.view.WindowManager
|
||||
|
@ -19,7 +20,9 @@ import com.simplemobiletools.gallery.extensions.config
|
|||
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.PATH
|
||||
import com.simplemobiletools.gallery.helpers.PLAY_PAUSE_VISIBLE_ALPHA
|
||||
import kotlinx.android.synthetic.main.activity_panorama_video.*
|
||||
import java.io.File
|
||||
|
||||
|
@ -27,6 +30,9 @@ open class PanoramaVideoActivity : SimpleActivity() {
|
|||
private var isFullScreen = false
|
||||
private var isExploreEnabled = true
|
||||
private var isRendering = false
|
||||
private var isPlaying = true
|
||||
|
||||
private var mHidePlayPauseHandler = Handler()
|
||||
|
||||
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||
useDynamicTheme = false
|
||||
|
@ -80,6 +86,10 @@ open class PanoramaVideoActivity : SimpleActivity() {
|
|||
if (isRendering) {
|
||||
vr_video_view.shutdown()
|
||||
}
|
||||
|
||||
if (!isChangingConfigurations) {
|
||||
mHidePlayPauseHandler.removeCallbacksAndMessages(null)
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkIntent() {
|
||||
|
@ -98,6 +108,7 @@ open class PanoramaVideoActivity : SimpleActivity() {
|
|||
|
||||
vr_video_view.apply {
|
||||
loadVideo(Uri.fromFile(File(path)), options)
|
||||
schedulePlayPauseFadeOut()
|
||||
setFlingingEnabled(true)
|
||||
setPureTouchTracking(true)
|
||||
|
||||
|
@ -117,6 +128,10 @@ open class PanoramaVideoActivity : SimpleActivity() {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
video_play_outline.setOnClickListener {
|
||||
togglePlayPause()
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
showErrorToast(e)
|
||||
}
|
||||
|
@ -132,6 +147,37 @@ open class PanoramaVideoActivity : SimpleActivity() {
|
|||
setupButtonMargins()
|
||||
}
|
||||
|
||||
private fun togglePlayPause() {
|
||||
isPlaying = !isPlaying
|
||||
mHidePlayPauseHandler.removeCallbacksAndMessages(null)
|
||||
video_play_outline.alpha = PLAY_PAUSE_VISIBLE_ALPHA
|
||||
schedulePlayPauseFadeOut()
|
||||
if (isPlaying) {
|
||||
playVideo()
|
||||
} else {
|
||||
pauseVideo()
|
||||
}
|
||||
}
|
||||
|
||||
private fun playVideo() {
|
||||
vr_video_view.playVideo()
|
||||
video_play_outline.setImageResource(R.drawable.ic_pause)
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
}
|
||||
|
||||
private fun pauseVideo() {
|
||||
vr_video_view.pauseVideo()
|
||||
video_play_outline.setImageResource(R.drawable.ic_play)
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
}
|
||||
|
||||
private fun schedulePlayPauseFadeOut() {
|
||||
mHidePlayPauseHandler.removeCallbacksAndMessages(null)
|
||||
mHidePlayPauseHandler.postDelayed({
|
||||
video_play_outline.animate().alpha(0f).start()
|
||||
}, HIDE_PLAY_PAUSE_DELAY)
|
||||
}
|
||||
|
||||
private fun setupButtonMargins() {
|
||||
(explore.layoutParams as RelativeLayout.LayoutParams).bottomMargin = navigationBarHeight
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import com.simplemobiletools.gallery.activities.VideoActivity
|
|||
import com.simplemobiletools.gallery.extensions.*
|
||||
import com.simplemobiletools.gallery.helpers.*
|
||||
import com.simplemobiletools.gallery.models.Medium
|
||||
import kotlinx.android.synthetic.main.activity_panorama_video.*
|
||||
import kotlinx.android.synthetic.main.pager_video_item.view.*
|
||||
import java.io.File
|
||||
|
||||
|
@ -415,6 +416,7 @@ class VideoFragment : ViewPagerFragment(), TextureView.SurfaceTextureListener, S
|
|||
mIsPlaying = true
|
||||
mExoPlayer?.playWhenReady = true
|
||||
mView!!.video_play_outline.setImageResource(R.drawable.ic_pause)
|
||||
video_play_outline.alpha = PLAY_PAUSE_VISIBLE_ALPHA
|
||||
activity!!.window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
schedulePlayPauseFadeOut()
|
||||
}
|
||||
|
|
|
@ -20,4 +20,13 @@
|
|||
android:padding="@dimen/activity_margin"
|
||||
android:src="@drawable/ic_explore"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/video_play_outline"
|
||||
android:layout_width="@dimen/play_outline_size_big"
|
||||
android:layout_height="@dimen/play_outline_size_big"
|
||||
android:layout_centerInParent="true"
|
||||
android:background="@drawable/circle_black_background_with_inset"
|
||||
android:padding="26dp"
|
||||
android:src="@drawable/ic_pause"/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
|
Loading…
Reference in New Issue