From d94bda08ec723d29271fd3ea9e234e99ddfa1c49 Mon Sep 17 00:00:00 2001 From: ThibaultBee <37510686+ThibaultBee@users.noreply.github.com> Date: Mon, 30 Sep 2024 20:54:53 +0200 Subject: [PATCH] fix(lib): fix exception on startPreview --- .../java/video/api/livestream/ApiVideoLiveStream.kt | 12 ++++++++++-- .../java/video/api/livestream/views/ApiVideoView.kt | 11 ++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/livestream/src/main/java/video/api/livestream/ApiVideoLiveStream.kt b/livestream/src/main/java/video/api/livestream/ApiVideoLiveStream.kt index 289ed4e..fb80356 100644 --- a/livestream/src/main/java/video/api/livestream/ApiVideoLiveStream.kt +++ b/livestream/src/main/java/video/api/livestream/ApiVideoLiveStream.kt @@ -238,7 +238,11 @@ constructor( } init { - apiVideoView.streamer = streamer + try { + apiVideoView.streamer = streamer + } catch (e: Exception) { + Log.w(TAG, "Can't set streamer to ApiVideoView: ${e.message}") + } } /** @@ -370,7 +374,11 @@ constructor( Log.w(TAG, "Video config is not set") return@permissionRequester } - apiVideoView.startPreview() + try { + apiVideoView.startPreview() + } catch (t: Throwable) { + Log.e(TAG, "Can't start preview: ${t.message}") + } } } diff --git a/livestream/src/main/java/video/api/livestream/views/ApiVideoView.kt b/livestream/src/main/java/video/api/livestream/views/ApiVideoView.kt index fc08a0d..8647d54 100644 --- a/livestream/src/main/java/video/api/livestream/views/ApiVideoView.kt +++ b/livestream/src/main/java/video/api/livestream/views/ApiVideoView.kt @@ -2,6 +2,7 @@ package video.api.livestream.views import android.content.Context import android.util.AttributeSet +import android.util.Log import android.view.ViewGroup import android.widget.FrameLayout import io.github.thibaultbee.streampack.streamers.interfaces.ICameraStreamer @@ -25,7 +26,11 @@ class ApiVideoView @JvmOverloads constructor( * @param value the [ICameraStreamer] to use */ set(value) { - previewView.streamer = value + try { + previewView.streamer = value + } catch (t: Throwable) { + Log.w(TAG, "Failed to set streamer: $t") + } } init { @@ -61,4 +66,8 @@ class ApiVideoView @JvmOverloads constructor( internal fun startPreview() { previewView.startPreview() } + + companion object { + private const val TAG = "ApiVideoView" + } } \ No newline at end of file