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; } }