GstLibrary加上錯誤狀態

This commit is contained in:
Barney
2022-08-05 15:12:25 +08:00
parent 8afd65e63d
commit 3e6d7e9e1c
5 changed files with 17 additions and 24 deletions
@@ -1,7 +1,6 @@
package com.hisharp.gstreamer_player;
public interface GstCallback {
public void onStatus(GstLibrary gstInstance, GstStatus gstStatus);
public void onMessage(GstLibrary gstInstance, String message);
public void onMediaSizeChanged (GstLibrary gstInstance, int width, int height);
void onStatus(GstLibrary gstInstance, GstStatus gstStatus);
void onMessage(GstLibrary gstInstance, String message);
}
@@ -80,6 +80,8 @@ public class GstLibrary implements SurfaceHolder.Callback {
gstCallback.onStatus(this, GstStatus.PAUSE);
} else if (message.contains("State changed to PLAYING")) {
gstCallback.onStatus(this, GstStatus.PLAYING);
} else if (message.contains("Could not open resource for reading and writing")) {
gstCallback.onStatus(this, GstStatus.ERROR);
}
gstCallback.onMessage(this, message);
}
@@ -101,6 +103,17 @@ public class GstLibrary implements SurfaceHolder.Callback {
// Called from native code
private void setCurrentPosition(final int position, final int duration) {}
// Called from native code when the size of the media changes or is first detected.
// Inform the video surface about the new size and recalculate the layout.
private void onMediaSizeChanged (int width, int height) {
Log.i ("GStreamer", "Media size changed to " + width + "x" + height);
mainHandler.post(() -> {
surfaceView.media_width = width;
surfaceView.media_height = height;
surfaceView.requestLayout();
});
}
static {
System.loadLibrary("gstreamer_android");
System.loadLibrary("gst_player");
@@ -122,16 +135,4 @@ public class GstLibrary implements SurfaceHolder.Callback {
Log.d("GStreamer", "Surface destroyed");
nativeSurfaceFinalize();
}
// Called from native code when the size of the media changes or is first detected.
// Inform the video surface about the new size and recalculate the layout.
private void onMediaSizeChanged (int width, int height) {
Log.i ("GStreamer", "Media size changed to " + width + "x" + height);
mainHandler.post(() -> {
surfaceView.media_width = width;
surfaceView.media_height = height;
surfaceView.requestLayout();
});
}
}
@@ -3,5 +3,6 @@ package com.hisharp.gstreamer_player;
public enum GstStatus {
READY,
PAUSE,
PLAYING
PLAYING,
ERROR
}