Skip to content

Commit 90bec5f

Browse files
committed
fixed a bug where capture would fail depending on the execution order of MediaMixer.startRunning.
1 parent a56f78e commit 90bec5f

File tree

3 files changed

+24
-7
lines changed

3 files changed

+24
-7
lines changed

app/src/main/java/com/haishinkit/app/CameraViewModel.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ class CameraViewModel(
146146
Screen.DEFAULT_HEIGHT,
147147
)
148148
}
149+
150+
Configuration.ORIENTATION_SQUARE -> {
151+
}
152+
153+
Configuration.ORIENTATION_UNDEFINED -> {
154+
}
149155
}
150156
}
151157

haishinkit/src/main/java/com/haishinkit/media/MediaMixer.kt

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,12 @@ class MediaMixer(
126126
if (video is Camera2Source) {
127127
video.isTorchEnabled = isToucheEnabled
128128
}
129-
return video.open(this).onSuccess {
130-
screen.attachVideo(track, video)
129+
return if (isRunning.get()) {
130+
video.open(this).onSuccess {
131+
screen.attachVideo(track, video)
132+
}
133+
} else {
134+
Result.success(Unit)
131135
}
132136
}
133137
videoSources.remove(track)?.let {
@@ -173,8 +177,12 @@ class MediaMixer(
173177
orientationEventListener.enable()
174178
startAudioCapturing()
175179
launch {
176-
videoSources.values.forEach {
177-
it.open(this@MediaMixer)
180+
videoSources.forEach {
181+
val track = it.key
182+
val source = it.value
183+
source.open(this@MediaMixer).onSuccess {
184+
screen.attachVideo(track, source)
185+
}
178186
}
179187
}
180188
isRunning.set(true)
@@ -187,8 +195,11 @@ class MediaMixer(
187195
keepAlive = false
188196
orientationEventListener.disable()
189197
launch {
190-
videoSources.values.forEach {
191-
it.close()
198+
videoSources.forEach {
199+
val track = it.key
200+
val source = it.value
201+
source.close()
202+
screen.attachVideo(track, null)
192203
}
193204
}
194205
isRunning.set(false)

haishinkit/src/main/java/com/haishinkit/screen/scene/ScreenObjectSnapshot.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ data class ScreenObjectSnapshot(
5757
@Serializable
5858
data class Size(
5959
val width: Int,
60-
val height: Int
60+
val height: Int,
6161
)
6262
}

0 commit comments

Comments
 (0)