加入初始化旗標

This commit is contained in:
Raymond Yang 2023-03-07 11:55:54 +08:00
parent 48db07290c
commit e3c958c632
2 changed files with 15 additions and 5 deletions

View File

@ -71,7 +71,7 @@ class SplitViewFragment : Fragment() {
} }
override fun onPause() { override fun onPause() {
//stopAll() stopAll()
super.onPause() super.onPause()
Log.d("${TAG}_$mPageNum", "onPause()") Log.d("${TAG}_$mPageNum", "onPause()")
} }
@ -201,15 +201,15 @@ class SplitViewFragment : Fragment() {
} }
}.start() }.start()
fun stopAll() /*= MainScope().launch(Dispatchers.Main)*/ { fun stopAll() = MainScope().launch(Dispatchers.Main) {
if (videoViews.isEmpty()) return if (videoViews.isEmpty()) return@launch
for (index in data.indices) { for (index in data.indices) {
videoViews[index].stopRetryCount() videoViews[index].stopRetryCount()
if (!videoViews[index].isPlaying || videoViews[index].isLoading) continue if (!videoViews[index].isPlaying || videoViews[index].isLoading) continue
videoViews[index].stop() videoViews[index].stop()
//delay(300) //delay(300)
} }
}//.start() }.start()
fun destroyAll() /*= MainScope().launch(Dispatchers.Main)*/ { fun destroyAll() /*= MainScope().launch(Dispatchers.Main)*/ {
if (videoViews.isEmpty()) return if (videoViews.isEmpty()) return

View File

@ -25,6 +25,8 @@ public class GstLibrary implements Closeable, SurfaceHolder.Callback {
private String tag = ""; private String tag = "";
private Boolean isInit = false;
public GstLibrary(Context context) { public GstLibrary(Context context) {
this.mAppContext = context.getApplicationContext(); 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"; //private final String defaultMediaUri = "rtsp://admin:admin@192.168.0.77:554/media/video2";
public void play() { public void play() {
if (!isInit) return;
nativePlay(); nativePlay();
} }
public void stop() { public void stop() {
if (!isInit) return;
nativePause(); nativePause();
} }
@ -70,6 +74,7 @@ public class GstLibrary implements Closeable, SurfaceHolder.Callback {
} }
public void releaseSurface() { public void releaseSurface() {
isInit = false;
nativeSurfaceFinalize(); nativeSurfaceFinalize();
} }
@ -113,6 +118,8 @@ public class GstLibrary implements Closeable, SurfaceHolder.Callback {
if (rtspUrl != null) { if (rtspUrl != null) {
nativeSetUri(rtspUrl); nativeSetUri(rtspUrl);
} }
isInit = true;
} }
// Called from native code when the size of the media changes or is first detected. // 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 @Override
public void close() throws IOException { public void close() throws IOException {
isInit = false;
try { try {
nativeFinalize(); nativeFinalize();
} catch (Exception e) { } catch (Exception e) {
@ -144,7 +152,8 @@ public class GstLibrary implements Closeable, SurfaceHolder.Callback {
@Override @Override
public void surfaceCreated(SurfaceHolder holder) { public void surfaceCreated(SurfaceHolder holder) {
Log.d(TAG + "+" + tag, "Surface created: " + holder.getSurface()); 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()); nativeSurfaceInit(holder.getSurface());
} }
@ -158,5 +167,6 @@ public class GstLibrary implements Closeable, SurfaceHolder.Callback {
public void surfaceDestroyed(SurfaceHolder holder) { public void surfaceDestroyed(SurfaceHolder holder) {
Log.d(TAG + "+" + tag, "Surface destroyed"); Log.d(TAG + "+" + tag, "Surface destroyed");
releaseSurface(); releaseSurface();
isInit = false;
} }
} }