Skip to content

Commit

Permalink
Fix camera disable (#1254)
Browse files Browse the repository at this point in the history
  • Loading branch information
liviu-timar authored Dec 17, 2024
1 parent 05771a0 commit a048ff9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -586,13 +586,12 @@ public class CameraManager(
}

fun disable(fromUser: Boolean = true) {
if (fromUser) _status.value = DeviceStatus.Disabled

if (isCapturingVideo) {
// 1. update our local state
// 2. update the track enabled status
// 3. Rtc listens and sends the update mute state request
if (fromUser) {
_status.value = DeviceStatus.Disabled
}
mediaManager.videoTrack.trySetEnabled(false)
videoCapturer.stopCapture()
isCapturingVideo = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@

package io.getstream.video.android.tutorial.livestream

import android.widget.Toast
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import io.getstream.log.Priority
import io.getstream.video.android.compose.permission.LaunchCallPermissions
import io.getstream.video.android.compose.ui.components.call.CallAppBar
import io.getstream.video.android.compose.ui.components.livestream.LivestreamPlayer
import io.getstream.video.android.core.GEO
Expand Down Expand Up @@ -67,11 +65,11 @@ fun LiveAudience(

// step3 - join a call, which type is `default` and id is `123`.
val call = client.call("livestream", callId)
LaunchCallPermissions(call = call) {
val result = call.join()
result.onError {
Toast.makeText(context, "uh oh $it", Toast.LENGTH_SHORT).show()
}

LaunchedEffect(call) {
call.microphone.setEnabled(false, fromUser = true)
call.camera.setEnabled(false, fromUser = true)
call.join()
}

Box {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ import androidx.navigation.NavController
import io.getstream.log.Priority
import io.getstream.video.android.compose.permission.LaunchCallPermissions
import io.getstream.video.android.compose.theme.VideoTheme
import io.getstream.video.android.compose.ui.components.call.controls.actions.FlipCameraAction
import io.getstream.video.android.compose.ui.components.call.controls.actions.LeaveCallAction
import io.getstream.video.android.compose.ui.components.call.controls.actions.ToggleCameraAction
import io.getstream.video.android.compose.ui.components.video.VideoRenderer
import io.getstream.video.android.core.Call
import io.getstream.video.android.core.GEO
Expand Down Expand Up @@ -158,6 +160,8 @@ private fun LiveHostContent(
}
},
bottomBar = {
val isCameraEnabled by call.camera.isEnabled.collectAsState()

Row {
Button(
colors = ButtonDefaults.buttonColors(
Expand All @@ -176,6 +180,14 @@ private fun LiveHostContent(
)
}
Spacer(modifier = Modifier.width(16.dp))
ToggleCameraAction(isCameraEnabled = isCameraEnabled) {
call.camera.setEnabled(it.isEnabled)
}
Spacer(modifier = Modifier.width(16.dp))
FlipCameraAction {
call.camera.flip()
}
Spacer(modifier = Modifier.width(16.dp))
LeaveCallAction {
call.leave()
navController.popBackStack()
Expand Down

0 comments on commit a048ff9

Please sign in to comment.