@@ -49,7 +49,6 @@ import com.mrousavy.camera.utils.ImageFormatUtils
49
49
import java.io.Closeable
50
50
import java.lang.IllegalStateException
51
51
import java.util.concurrent.CancellationException
52
- import kotlin.coroutines.CoroutineContext
53
52
import kotlinx.coroutines.CoroutineScope
54
53
import kotlinx.coroutines.launch
55
54
import kotlinx.coroutines.runBlocking
@@ -58,8 +57,7 @@ import kotlinx.coroutines.sync.withLock
58
57
59
58
class CameraSession (private val context : Context , private val cameraManager : CameraManager , private val callback : Callback ) :
60
59
CameraManager .AvailabilityCallback (),
61
- Closeable ,
62
- CoroutineScope {
60
+ Closeable {
63
61
companion object {
64
62
private const val TAG = " CameraSession"
65
63
}
@@ -95,8 +93,7 @@ class CameraSession(private val context: Context, private val cameraManager: Cam
95
93
field = value
96
94
}
97
95
98
- override val coroutineContext: CoroutineContext
99
- get() = CameraQueues .cameraQueue.coroutineDispatcher
96
+ private val coroutineScope = CoroutineScope (CameraQueues .cameraQueue.coroutineDispatcher)
100
97
101
98
// Video Outputs
102
99
private var recording: RecordingSession ? = null
@@ -139,7 +136,7 @@ class CameraSession(private val context: Context, private val cameraManager: Cam
139
136
super .onCameraAvailable(cameraId)
140
137
if (this .configuration?.cameraId == cameraId && cameraDevice == null && configuration?.isActive == true ) {
141
138
Log .i(TAG , " Camera #$cameraId is now available again, trying to re-open it now..." )
142
- launch {
139
+ coroutineScope. launch {
143
140
configure {
144
141
// re-open CameraDevice if needed
145
142
}
@@ -252,7 +249,7 @@ class CameraSession(private val context: Context, private val cameraManager: Cam
252
249
253
250
private fun createPreviewOutput (surface : Surface ) {
254
251
Log .i(TAG , " Setting Preview Output..." )
255
- launch {
252
+ coroutineScope. launch {
256
253
configure { config ->
257
254
config.preview = CameraConfiguration .Output .Enabled .create(CameraConfiguration .Preview (surface))
258
255
}
0 commit comments