加入初始化旗標
This commit is contained in:
parent
48db07290c
commit
e3c958c632
@ -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
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user