加入初始化旗標

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