Skip to content

Commit

Permalink
fix(demos): camera: do not release streamer in the lifecycle observer…
Browse files Browse the repository at this point in the history
…. Only the view model `onCleared` call release as streamer is persisted throught application lifecycle.
  • Loading branch information
ThibaultBee committed Oct 3, 2024
1 parent 4e53f71 commit 916f26d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import kotlinx.coroutines.runBlocking
*
* @param streamer The streamer to observe
*/
open class StreamerLifeCycleObserver(val streamer: ICoroutineStreamer) : DefaultLifecycleObserver {
open class StreamerLifeCycleObserver(protected val streamer: ICoroutineStreamer) :
DefaultLifecycleObserver {
override fun onPause(owner: LifecycleOwner) {
if (streamer is ICameraStreamer) {
streamer.stopPreview()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import android.net.Uri
import android.os.Build
import android.util.Range
import androidx.annotation.RequiresPermission
import androidx.lifecycle.LifecycleOwner
import io.github.thibaultbee.streampack.app.configuration.Configuration
import io.github.thibaultbee.streampack.app.models.EndpointType
import io.github.thibaultbee.streampack.app.models.FileExtension
Expand Down Expand Up @@ -61,7 +62,7 @@ class StreamerManager(
get() = (streamer as ICameraStreamer?)?.videoSource?.cameraId

val streamerLifeCycleObserver: StreamerLifeCycleObserver by lazy {
StreamerLifeCycleObserver(streamer)
CustomStreamerLifeCycleObserver(streamer)
}

val requiredPermissions: List<String>
Expand Down Expand Up @@ -242,4 +243,12 @@ class StreamerManager(
set(value) {
streamer.audioSource?.isMuted = value
}

class CustomStreamerLifeCycleObserver(streamer: ICoroutineStreamer) :
StreamerLifeCycleObserver(streamer) {
override fun onDestroy(owner: LifecycleOwner) {
// Do nothing
// The ViewModel onCleared() method will call release() method
}
}
}

0 comments on commit 916f26d

Please sign in to comment.