From 3e6d7e9e1c139929a1cd10dbc0cd08630762fe7a Mon Sep 17 00:00:00 2001 From: Barney Date: Fri, 5 Aug 2022 15:12:25 +0800 Subject: [PATCH] =?UTF-8?q?GstLibrary=E5=8A=A0=E4=B8=8A=E9=8C=AF=E8=AA=A4?= =?UTF-8?q?=E7=8B=80=E6=85=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../gstreamer_demo_app/GridVideoFragment.kt | 7 ------ app/src/main/res/layout/item_video_view.xml | 1 - .../hisharp/gstreamer_player/GstCallback.java | 5 ++-- .../hisharp/gstreamer_player/GstLibrary.java | 25 ++++++++++--------- .../hisharp/gstreamer_player/GstStatus.java | 3 ++- 5 files changed, 17 insertions(+), 24 deletions(-) diff --git a/app/src/main/java/com/ray650128/gstreamer_demo_app/GridVideoFragment.kt b/app/src/main/java/com/ray650128/gstreamer_demo_app/GridVideoFragment.kt index 2470f96..7def1d5 100644 --- a/app/src/main/java/com/ray650128/gstreamer_demo_app/GridVideoFragment.kt +++ b/app/src/main/java/com/ray650128/gstreamer_demo_app/GridVideoFragment.kt @@ -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" diff --git a/app/src/main/res/layout/item_video_view.xml b/app/src/main/res/layout/item_video_view.xml index c262d08..6484d04 100644 --- a/app/src/main/res/layout/item_video_view.xml +++ b/app/src/main/res/layout/item_video_view.xml @@ -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" diff --git a/gstreamer_player/src/com/hisharp/gstreamer_player/GstCallback.java b/gstreamer_player/src/com/hisharp/gstreamer_player/GstCallback.java index a981c34..953c9e8 100644 --- a/gstreamer_player/src/com/hisharp/gstreamer_player/GstCallback.java +++ b/gstreamer_player/src/com/hisharp/gstreamer_player/GstCallback.java @@ -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); } diff --git a/gstreamer_player/src/com/hisharp/gstreamer_player/GstLibrary.java b/gstreamer_player/src/com/hisharp/gstreamer_player/GstLibrary.java index c4e7f96..c980760 100644 --- a/gstreamer_player/src/com/hisharp/gstreamer_player/GstLibrary.java +++ b/gstreamer_player/src/com/hisharp/gstreamer_player/GstLibrary.java @@ -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(); - }); - - } } diff --git a/gstreamer_player/src/com/hisharp/gstreamer_player/GstStatus.java b/gstreamer_player/src/com/hisharp/gstreamer_player/GstStatus.java index 47f8c24..e511276 100644 --- a/gstreamer_player/src/com/hisharp/gstreamer_player/GstStatus.java +++ b/gstreamer_player/src/com/hisharp/gstreamer_player/GstStatus.java @@ -3,5 +3,6 @@ package com.hisharp.gstreamer_player; public enum GstStatus { READY, PAUSE, - PLAYING + PLAYING, + ERROR }