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

View File

@ -91,11 +91,6 @@ class GridVideoFragment : Fragment(), GstCallback {
}
private fun initView() {
binding.baseView.setBackgroundColor(Color.rgb(
(0..255).random(),
(0..255).random(),
(0..255).random()
))
val maxRow = sqrt(splitMode.toFloat()).toInt()
val maxCol = sqrt(splitMode.toFloat()).toInt()
@ -199,8 +194,6 @@ class GridVideoFragment : Fragment(), GstCallback {
Log.d("${TAG}_$mPageNum", "GstPlayer #$index: $message")
}
override fun onMediaSizeChanged(gstInstance: GstLibrary, width: Int, height: Int) {}
companion object {
private val TAG = GridVideoFragment::class.java.simpleName
private const val ARG_PAGE_NUM = "page_number"

View File

@ -22,7 +22,6 @@
android:layout_width="0dp"
android:layout_height="0dp"
android:scaleType="fitXY"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"

View File

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

View File

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

View File

@ -3,5 +3,6 @@ package com.hisharp.gstreamer_player;
public enum GstStatus {
READY,
PAUSE,
PLAYING
PLAYING,
ERROR
}