From e3c958c632bc2e44e46852a0318bafc3262adeea Mon Sep 17 00:00:00 2001 From: Raymond Yang Date: Tue, 7 Mar 2023 11:55:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8A=A0=E5=85=A5=E5=88=9D=E5=A7=8B=E5=8C=96?= =?UTF-8?q?=E6=97=97=E6=A8=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ui/mainScreen/SplitViewFragment.kt | 8 ++++---- .../src/com/hisharp/gstreamer_player/GstLibrary.java | 12 +++++++++++- 2 files changed, 15 insertions(+), 5 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 efed992..298d17c 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 @@ -71,7 +71,7 @@ class SplitViewFragment : Fragment() { } override fun onPause() { - //stopAll() + stopAll() super.onPause() Log.d("${TAG}_$mPageNum", "onPause()") } @@ -201,15 +201,15 @@ class SplitViewFragment : Fragment() { } }.start() - fun stopAll() /*= MainScope().launch(Dispatchers.Main)*/ { - if (videoViews.isEmpty()) return + fun stopAll() = MainScope().launch(Dispatchers.Main) { + if (videoViews.isEmpty()) return@launch for (index in data.indices) { videoViews[index].stopRetryCount() if (!videoViews[index].isPlaying || videoViews[index].isLoading) continue videoViews[index].stop() //delay(300) } - }//.start() + }.start() fun destroyAll() /*= MainScope().launch(Dispatchers.Main)*/ { if (videoViews.isEmpty()) return diff --git a/gstreamer_player/src/com/hisharp/gstreamer_player/GstLibrary.java b/gstreamer_player/src/com/hisharp/gstreamer_player/GstLibrary.java index ecc6637..781e4cf 100644 --- a/gstreamer_player/src/com/hisharp/gstreamer_player/GstLibrary.java +++ b/gstreamer_player/src/com/hisharp/gstreamer_player/GstLibrary.java @@ -25,6 +25,8 @@ public class GstLibrary implements Closeable, SurfaceHolder.Callback { private String tag = ""; + private Boolean isInit = false; + public GstLibrary(Context context) { this.mAppContext = context.getApplicationContext(); @@ -53,10 +55,12 @@ public class GstLibrary implements Closeable, SurfaceHolder.Callback { //private final String defaultMediaUri = "rtsp://admin:admin@192.168.0.77:554/media/video2"; public void play() { + if (!isInit) return; nativePlay(); } public void stop() { + if (!isInit) return; nativePause(); } @@ -70,6 +74,7 @@ public class GstLibrary implements Closeable, SurfaceHolder.Callback { } public void releaseSurface() { + isInit = false; nativeSurfaceFinalize(); } @@ -113,6 +118,8 @@ public class GstLibrary implements Closeable, SurfaceHolder.Callback { if (rtspUrl != null) { nativeSetUri(rtspUrl); } + + isInit = true; } // Called from native code when the size of the media changes or is first detected. @@ -134,6 +141,7 @@ public class GstLibrary implements Closeable, SurfaceHolder.Callback { @Override public void close() throws IOException { + isInit = false; try { nativeFinalize(); } catch (Exception e) { @@ -144,7 +152,8 @@ public class GstLibrary implements Closeable, SurfaceHolder.Callback { @Override public void surfaceCreated(SurfaceHolder holder) { Log.d(TAG + "+" + tag, "Surface created: " + holder.getSurface()); - Log.i (TAG + "+" + tag, "GStreamer surfaceCreated:"); + Log.i (TAG + "+" + tag, "GStreamer surfaceCreated"); + isInit = true; nativeSurfaceInit(holder.getSurface()); } @@ -158,5 +167,6 @@ public class GstLibrary implements Closeable, SurfaceHolder.Callback { public void surfaceDestroyed(SurfaceHolder holder) { Log.d(TAG + "+" + tag, "Surface destroyed"); releaseSurface(); + isInit = false; } }