Skip to content

Commit

Permalink
fix(core): use single streamer instead of coroutine single streamer
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibaultBee committed Jan 6, 2025
1 parent d4511e4 commit 2b67e83
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ package io.github.thibaultbee.streampack.core.streamers.observers

import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import io.github.thibaultbee.streampack.core.streamers.single.ICoroutineSingleStreamer
import io.github.thibaultbee.streampack.core.streamers.single.ISingleStreamer

/**
* A [DefaultLifecycleObserver] to control a streamer on [Activity] lifecycle.
Expand All @@ -29,7 +29,7 @@ import io.github.thibaultbee.streampack.core.streamers.single.ICoroutineSingleSt
*
* @param streamer The streamer to control
*/
open class StreamerActivityLifeCycleObserver(streamer: ICoroutineSingleStreamer) :
open class StreamerActivityLifeCycleObserver(streamer: ISingleStreamer) :
StreamerViewModelLifeCycleObserver(streamer) {
override fun onDestroy(owner: LifecycleOwner) {
streamer.release()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@ package io.github.thibaultbee.streampack.core.streamers.observers

import androidx.lifecycle.DefaultLifecycleObserver
import androidx.lifecycle.LifecycleOwner
import io.github.thibaultbee.streampack.core.streamers.interfaces.ICameraStreamer
import io.github.thibaultbee.streampack.core.streamers.interfaces.ICameraCallbackStreamer
import io.github.thibaultbee.streampack.core.streamers.interfaces.ICameraCoroutineStreamer
import io.github.thibaultbee.streampack.core.streamers.single.ICallbackSingleStreamer
import io.github.thibaultbee.streampack.core.streamers.single.ICoroutineSingleStreamer
import io.github.thibaultbee.streampack.core.streamers.single.ISingleStreamer
import kotlinx.coroutines.runBlocking

/**
Expand All @@ -31,17 +34,29 @@ import kotlinx.coroutines.runBlocking
*
* @param streamer The streamer to control
*/
open class StreamerViewModelLifeCycleObserver(protected val streamer: ICoroutineSingleStreamer) :
open class StreamerViewModelLifeCycleObserver(protected val streamer: ISingleStreamer) :
DefaultLifecycleObserver {
override fun onPause(owner: LifecycleOwner) {
if (streamer is ICameraStreamer) {
streamer.stopPreview()
}
runBlocking {
if (streamer is ICoroutineSingleStreamer) {
if (streamer is ICameraCoroutineStreamer) {
runBlocking { streamer.stopPreview() }
}
runBlocking {
streamer.stopStream()
if (streamer.endpoint.isOpen.value) {
streamer.close()
}
}
} else if (streamer is ICallbackSingleStreamer) {
if (streamer is ICameraCallbackStreamer) {
streamer.stopPreview()
}
streamer.stopStream()
if (streamer.endpoint.isOpen.value) {
streamer.close()
}
} else {
throw IllegalArgumentException("Streamer is unknown")
}
}
}

0 comments on commit 2b67e83

Please sign in to comment.