From 792ebc70c25ebd4445470c904d60ce26e1bda6d9 Mon Sep 17 00:00:00 2001 From: Raymond Yang Date: Wed, 1 Feb 2023 10:38:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=87VideoView=E7=9A=84retryCount=E5=B0=81?= =?UTF-8?q?=E8=A3=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/mainScreen/SplitViewFragment.kt | 5 ++-- .../ui/mainScreen/VideoView.kt | 23 ++++++++++--------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/ray650128/gstreamer_demo_app/ui/mainScreen/SplitViewFragment.kt b/app/src/main/java/com/ray650128/gstreamer_demo_app/ui/mainScreen/SplitViewFragment.kt index 4b4ee53..f577906 100644 --- a/app/src/main/java/com/ray650128/gstreamer_demo_app/ui/mainScreen/SplitViewFragment.kt +++ b/app/src/main/java/com/ray650128/gstreamer_demo_app/ui/mainScreen/SplitViewFragment.kt @@ -132,7 +132,7 @@ class SplitViewFragment : Fragment() { if (position >= data.size) return@setOnClickListener if (!videoViews[position].isPlaying) { if (!videoViews[position].isLoading) { - videoViews[position].retryCount = 0 + videoViews[position].resetRetryCount() videoViews[position].play() } return@setOnClickListener @@ -166,7 +166,7 @@ class SplitViewFragment : Fragment() { fun playAll() = MainScope().launch(Dispatchers.Main) { if (videoViews.isEmpty()) return@launch for (index in data.indices) { - videoViews[index].retryCount = 0 + videoViews[index].resetRetryCount() videoViews[index].play() delay(300) } @@ -174,6 +174,7 @@ class SplitViewFragment : Fragment() { fun stopAll() = MainScope().launch(Dispatchers.Main) { for (index in data.indices) { + videoViews[index].stopRetryCount() videoViews[index].stop() delay(300) } diff --git a/app/src/main/java/com/ray650128/gstreamer_demo_app/ui/mainScreen/VideoView.kt b/app/src/main/java/com/ray650128/gstreamer_demo_app/ui/mainScreen/VideoView.kt index 733ca42..304a273 100644 --- a/app/src/main/java/com/ray650128/gstreamer_demo_app/ui/mainScreen/VideoView.kt +++ b/app/src/main/java/com/ray650128/gstreamer_demo_app/ui/mainScreen/VideoView.kt @@ -47,7 +47,7 @@ class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback { field = value } - var retryCount = 0 + private var retryCount = 0 private var retryRunnable = object : Runnable { override fun run() { play() @@ -99,26 +99,27 @@ class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback { } fun play() { - /*if (retryCount == RETRY_OFF) { - return - }*/ videoView.postInvalidate() gstLibrary.play() } fun stop() { isPlaying = false - retryCount = RETRY_OFF if (this::gstLibrary.isInitialized) { gstLibrary.stop() } } + fun resetRetryCount() { + retryCount = 0 + } + + fun stopRetryCount() { + retryCount = RETRY_OFF + } + override fun surfaceCreated(holder: SurfaceHolder) { Log.d("${TAG}_$tag", "Surface created: " + holder.surface) - if (this::gstLibrary.isInitialized) { - gstLibrary.setSurfaceHolder(holder) - } } override fun surfaceChanged(holder: SurfaceHolder, format: Int, width: Int, height: Int) { @@ -130,7 +131,7 @@ class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback { override fun surfaceDestroyed(p0: SurfaceHolder) { Log.d("${TAG}_$tag", "Surface destroyed") - // TODO: 如果呼叫 releaseSurface(),會閃退 + // TODO: 呼叫 releaseSurface() 會閃退,目前仍在釐清時機點 if (this::gstLibrary.isInitialized) { gstLibrary.releaseSurface() } @@ -162,7 +163,7 @@ class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback { MSG_PLAY -> { isLoading = false isPlaying = true - retryCount = 0 + resetRetryCount() } MSG_BUFFERING -> { isLoading = true @@ -173,7 +174,7 @@ class VideoView : ConstraintLayout, SurfaceHolder.Callback, GstCallback { mHandler.post(retryRunnable) retryCount++ } else { - retryCount = RETRY_OFF + stopRetryCount() //Log.e("${TAG}_$tag", "Retry count = 5, stopped retry...") } }