Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to implement pip content for AudioRoomContent #1083

Merged
merged 4 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ public final class io/getstream/video/android/compose/ui/components/audio/AudioR
}

public final class io/getstream/video/android/compose/ui/components/audio/AudioRoomContentKt {
public static final fun AudioRoomContent (Landroidx/compose/ui/Modifier;Lio/getstream/video/android/core/Call;ZLio/getstream/video/android/compose/permission/VideoPermissionsState;Ljava/lang/String;Lkotlin/jvm/functions/Function3;Lio/getstream/video/android/compose/ui/components/audio/AudioRendererStyle;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;III)V
public static final fun AudioRoomContent (Landroidx/compose/ui/Modifier;Lio/getstream/video/android/core/Call;ZLio/getstream/video/android/compose/permission/VideoPermissionsState;Ljava/lang/String;Lkotlin/jvm/functions/Function3;Lio/getstream/video/android/compose/ui/components/audio/AudioRendererStyle;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function0;Lkotlin/jvm/functions/Function0;ZLkotlin/jvm/functions/Function4;Lkotlin/jvm/functions/Function3;Landroidx/compose/runtime/Composer;III)V
}

public final class io/getstream/video/android/compose/ui/components/audio/ComposableSingletons$AudioAppBarKt {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package io.getstream.video.android.compose.ui.components.audio

import android.content.res.Configuration
import androidx.activity.compose.BackHandler
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.BoxScope
Expand All @@ -27,7 +28,9 @@ import androidx.compose.material.Scaffold
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.platform.LocalInspectionMode
import androidx.compose.ui.platform.testTag
Expand All @@ -36,8 +39,12 @@ import androidx.compose.ui.tooling.preview.Devices
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
import io.getstream.log.StreamLog
import io.getstream.video.android.compose.lifecycle.MediaPiPLifecycle
import io.getstream.video.android.compose.permission.VideoPermissionsState
import io.getstream.video.android.compose.permission.rememberMicrophonePermissionState
import io.getstream.video.android.compose.pip.enterPictureInPicture
import io.getstream.video.android.compose.pip.isInPictureInPictureMode
import io.getstream.video.android.compose.theme.VideoTheme
import io.getstream.video.android.core.Call
import io.getstream.video.android.core.ParticipantState
Expand All @@ -55,6 +62,8 @@ import io.getstream.video.android.mock.previewCall
* @param controlsContent Content is shown that allows users to trigger different actions to control a joined call.
* @param audioRenderer A single audio renderer renders each individual participant.
* @param onLeaveRoom A lambda that will be invoked when the leave quietly button was clicked.
* @param enableInPictureInPicture If the user has engaged in Picture-In-Picture mode.
* @param pictureInPictureContent Content shown when the user enters Picture in Picture mode, if it's been enabled in the app.
* @param audioContent Content is shown by rendering audio when we're connected to a call successfully.
*/
@Composable
Expand Down Expand Up @@ -95,6 +104,12 @@ public fun AudioRoomContent(
)
},
onLeaveRoom: (() -> Unit)? = null,
onBackPressed: () -> Unit = {},
enableInPictureInPicture: Boolean = true,
pictureInPictureContent: @Composable (
call: Call,
orientation: Int,
) -> Unit = { call, _ -> DefaultPictureInPictureContent(call, audioContent) },
controlsContent: @Composable (call: Call) -> Unit = {
AudioControlActions(
modifier = Modifier
Expand All @@ -105,29 +120,67 @@ public fun AudioRoomContent(
)
},
) {
val context = LocalContext.current
val orientation = LocalConfiguration.current.orientation
val isInPictureInPicture = context.isInPictureInPictureMode

DefaultPermissionHandler(videoPermission = permissions)

Scaffold(
modifier = modifier
.background(VideoTheme.colors.baseSheetPrimary)
.padding(32.dp),
contentColor = VideoTheme.colors.baseSheetPrimary,
topBar = {
if (isShowingAppBar) {
appBarContent.invoke(call)
}
},
bottomBar = { controlsContent.invoke(call) },
content = { paddings ->
Box(
modifier = Modifier
.background(color = VideoTheme.colors.baseSheetPrimary)
.padding(paddings),
) {
audioContent.invoke(this, call)
}
},
MediaPiPLifecycle(
call = call,
enableInPictureInPicture = enableInPictureInPicture,
)

BackHandler {
if (enableInPictureInPicture) {
try {
enterPictureInPicture(context = context, call = call)
} catch (e: Exception) {
StreamLog.e(tag = "AudioRoomContent") { e.stackTraceToString() }
call.leave()
}
} else {
onBackPressed.invoke()
}
}

if (isInPictureInPicture && enableInPictureInPicture) {
pictureInPictureContent(call, orientation)
} else {
Scaffold(
modifier = modifier
.background(VideoTheme.colors.baseSheetPrimary)
.padding(32.dp),
contentColor = VideoTheme.colors.baseSheetPrimary,
topBar = {
if (isShowingAppBar) {
appBarContent.invoke(call)
}
},
bottomBar = { controlsContent.invoke(call) },
content = { paddings ->
Box(
modifier = Modifier
.background(color = VideoTheme.colors.baseSheetPrimary)
.padding(paddings),
) {
audioContent.invoke(this, call)
}
},
)
}
}

@Composable
internal fun DefaultPictureInPictureContent(
call: Call,
audioContent: @Composable BoxScope.(call: Call) -> Unit,
) {
Box(
modifier = Modifier.background(color = VideoTheme.colors.baseSheetPrimary),
) {
audioContent.invoke(this, call)
}
}

@Composable
Expand Down
2 changes: 2 additions & 0 deletions tutorials/tutorial-audio/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@

<activity
android:name=".MainActivity"
android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation"
android:exported="true"
android:supportsPictureInPicture="true"
android:theme="@style/Theme.TutorialAudio">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ class MainActivity : ComponentActivity() {
AudioRoomContent(
call = call,
title = "Audio Room Number 05",
onLeaveRoom = {
call.leave()
finish()
},
)
} else {
Box(modifier = Modifier.fillMaxSize()) {
Expand Down
Loading