正在显示
3 个修改的文件
包含
20 行增加
和
0 行删除
| @@ -62,6 +62,7 @@ class CallActivity : AppCompatActivity() { | @@ -62,6 +62,7 @@ class CallActivity : AppCompatActivity() { | ||
| 62 | override fun onCreate(savedInstanceState: Bundle?) { | 62 | override fun onCreate(savedInstanceState: Bundle?) { |
| 63 | super.onCreate(savedInstanceState) | 63 | super.onCreate(savedInstanceState) |
| 64 | 64 | ||
| 65 | + // Obtain audio focus. | ||
| 65 | val audioManager = getSystemService(AUDIO_SERVICE) as AudioManager | 66 | val audioManager = getSystemService(AUDIO_SERVICE) as AudioManager |
| 66 | with(audioManager) { | 67 | with(audioManager) { |
| 67 | previousSpeakerphoneOn = isSpeakerphoneOn | 68 | previousSpeakerphoneOn = isSpeakerphoneOn |
| @@ -81,6 +82,7 @@ class CallActivity : AppCompatActivity() { | @@ -81,6 +82,7 @@ class CallActivity : AppCompatActivity() { | ||
| 81 | Timber.v { "Audio focus request failed" } | 82 | Timber.v { "Audio focus request failed" } |
| 82 | } | 83 | } |
| 83 | 84 | ||
| 85 | + // Setup compose view. | ||
| 84 | setContent { | 86 | setContent { |
| 85 | val room by viewModel.room.collectAsState() | 87 | val room by viewModel.room.collectAsState() |
| 86 | val participants by viewModel.participants.collectAsState(initial = emptyList()) | 88 | val participants by viewModel.participants.collectAsState(initial = emptyList()) |
| @@ -134,6 +136,7 @@ class CallActivity : AppCompatActivity() { | @@ -134,6 +136,7 @@ class CallActivity : AppCompatActivity() { | ||
| 134 | ) { | 136 | ) { |
| 135 | val (speakerView, audienceRow, buttonBar) = createRefs() | 137 | val (speakerView, audienceRow, buttonBar) = createRefs() |
| 136 | 138 | ||
| 139 | + // Primary speaker view | ||
| 137 | Surface(modifier = Modifier.constrainAs(speakerView) { | 140 | Surface(modifier = Modifier.constrainAs(speakerView) { |
| 138 | top.linkTo(parent.top) | 141 | top.linkTo(parent.top) |
| 139 | start.linkTo(parent.start) | 142 | start.linkTo(parent.start) |
| @@ -150,6 +153,8 @@ class CallActivity : AppCompatActivity() { | @@ -150,6 +153,8 @@ class CallActivity : AppCompatActivity() { | ||
| 150 | ) | 153 | ) |
| 151 | } | 154 | } |
| 152 | } | 155 | } |
| 156 | + | ||
| 157 | + // Audience row to display all participants. | ||
| 153 | LazyRow( | 158 | LazyRow( |
| 154 | modifier = Modifier | 159 | modifier = Modifier |
| 155 | .constrainAs(audienceRow) { | 160 | .constrainAs(audienceRow) { |
| @@ -178,6 +183,7 @@ class CallActivity : AppCompatActivity() { | @@ -178,6 +183,7 @@ class CallActivity : AppCompatActivity() { | ||
| 178 | } | 183 | } |
| 179 | } | 184 | } |
| 180 | 185 | ||
| 186 | + // Control bar for any switches such as mic/camera enable/disable. | ||
| 181 | Row( | 187 | Row( |
| 182 | modifier = Modifier | 188 | modifier = Modifier |
| 183 | .padding(top = 10.dp, bottom = 20.dp) | 189 | .padding(top = 10.dp, bottom = 20.dp) |
| @@ -272,6 +278,7 @@ class CallActivity : AppCompatActivity() { | @@ -272,6 +278,7 @@ class CallActivity : AppCompatActivity() { | ||
| 272 | override fun onDestroy() { | 278 | override fun onDestroy() { |
| 273 | super.onDestroy() | 279 | super.onDestroy() |
| 274 | 280 | ||
| 281 | + // release audio focus and revert audio settings. | ||
| 275 | val audioManager = getSystemService(AUDIO_SERVICE) as AudioManager | 282 | val audioManager = getSystemService(AUDIO_SERVICE) as AudioManager |
| 276 | with(audioManager) { | 283 | with(audioManager) { |
| 277 | isSpeakerphoneOn = previousSpeakerphoneOn | 284 | isSpeakerphoneOn = previousSpeakerphoneOn |
| @@ -23,6 +23,9 @@ import io.livekit.android.room.track.Track | @@ -23,6 +23,9 @@ import io.livekit.android.room.track.Track | ||
| 23 | import io.livekit.android.room.track.VideoTrack | 23 | import io.livekit.android.room.track.VideoTrack |
| 24 | import io.livekit.android.util.flow | 24 | import io.livekit.android.util.flow |
| 25 | 25 | ||
| 26 | +/** | ||
| 27 | + * Widget for displaying a participant. | ||
| 28 | + */ | ||
| 26 | @Composable | 29 | @Composable |
| 27 | fun ParticipantItem( | 30 | fun ParticipantItem( |
| 28 | room: Room, | 31 | room: Room, |
| @@ -14,6 +14,10 @@ import io.livekit.android.room.track.TrackPublication | @@ -14,6 +14,10 @@ import io.livekit.android.room.track.TrackPublication | ||
| 14 | import io.livekit.android.room.track.VideoTrack | 14 | import io.livekit.android.room.track.VideoTrack |
| 15 | import io.livekit.android.room.track.video.ComposeVisibility | 15 | import io.livekit.android.room.track.video.ComposeVisibility |
| 16 | 16 | ||
| 17 | +/** | ||
| 18 | + * Widget for displaying a VideoTrack. Handles the Compose <-> AndroidView interop needed to use | ||
| 19 | + * [TextureViewRenderer]. | ||
| 20 | + */ | ||
| 17 | @Composable | 21 | @Composable |
| 18 | fun VideoItem( | 22 | fun VideoItem( |
| 19 | room: Room, | 23 | room: Room, |
| @@ -23,6 +27,7 @@ fun VideoItem( | @@ -23,6 +27,7 @@ fun VideoItem( | ||
| 23 | val videoSinkVisibility = remember(room, videoTrack) { ComposeVisibility() } | 27 | val videoSinkVisibility = remember(room, videoTrack) { ComposeVisibility() } |
| 24 | var boundVideoTrack by remember { mutableStateOf<VideoTrack?>(null) } | 28 | var boundVideoTrack by remember { mutableStateOf<VideoTrack?>(null) } |
| 25 | var view: TextureViewRenderer? by remember { mutableStateOf(null) } | 29 | var view: TextureViewRenderer? by remember { mutableStateOf(null) } |
| 30 | + | ||
| 26 | fun cleanupVideoTrack() { | 31 | fun cleanupVideoTrack() { |
| 27 | view?.let { boundVideoTrack?.removeRenderer(it) } | 32 | view?.let { boundVideoTrack?.removeRenderer(it) } |
| 28 | boundVideoTrack = null | 33 | boundVideoTrack = null |
| @@ -42,12 +47,14 @@ fun VideoItem( | @@ -42,12 +47,14 @@ fun VideoItem( | ||
| 42 | videoTrack.addRenderer(view) | 47 | videoTrack.addRenderer(view) |
| 43 | } | 48 | } |
| 44 | } | 49 | } |
| 50 | + | ||
| 45 | DisposableEffect(room, videoTrack) { | 51 | DisposableEffect(room, videoTrack) { |
| 46 | onDispose { | 52 | onDispose { |
| 47 | videoSinkVisibility.onDispose() | 53 | videoSinkVisibility.onDispose() |
| 48 | cleanupVideoTrack() | 54 | cleanupVideoTrack() |
| 49 | } | 55 | } |
| 50 | } | 56 | } |
| 57 | + | ||
| 51 | AndroidView( | 58 | AndroidView( |
| 52 | factory = { context -> | 59 | factory = { context -> |
| 53 | TextureViewRenderer(context).apply { | 60 | TextureViewRenderer(context).apply { |
| @@ -65,6 +72,9 @@ fun VideoItem( | @@ -65,6 +72,9 @@ fun VideoItem( | ||
| 65 | ) | 72 | ) |
| 66 | } | 73 | } |
| 67 | 74 | ||
| 75 | +/** | ||
| 76 | + * This widget primarily serves as a way to observe changes in [videoTracks]. | ||
| 77 | + */ | ||
| 68 | @Composable | 78 | @Composable |
| 69 | fun VideoItemTrackSelector( | 79 | fun VideoItemTrackSelector( |
| 70 | room: Room, | 80 | room: Room, |
-
请 注册 或 登录 后发表评论