Skip to content

Issue/Feature: Unable manually control showControls property in real time #193

@Evleaps

Description

@Evleaps

Description:
I wanna manually set showControls based on my logic in real rime.

Example:

@Composable
private fun RemoteVideo(
    modifier: Modifier,
    showControls: Boolean,
    url: String,
) {
    val playerHost = rememberPlayerHost(url)
    val playerConfig = rememberPlayerConfig(showControls)
    playerConfig.showControls = showControls // user can manually show/hide controls 
    playerHost.onError = { err ->
        // intent
    }

    VideoPlayerComposable(
        modifier = modifier
            .clip(RoundedCornerShape(DesignSystem.radius.x16)),
        playerHost = playerHost,
        playerConfig = playerConfig,
    )
}

Cause:
We can't update *.showControls = !*.showControls because it keeps in remember in VideoPlayerComposable -> VideoPlayerWithControl.

@Composable
internal fun VideoPlayerWithControl(
    modifier: Modifier,
    playerHost: MediaPlayerHost,
    playerConfig: VideoPlayerConfig
) {
    var isScreenLocked by remember { mutableStateOf(false) }
    <---  here we keep value from config in remember and it survive recompositions  --->
    var showControls by remember { mutableStateOf(playerConfig.showControls) } // State for showing/hiding controls
    var showVolumeControl by remember { mutableStateOf(false) }
    var volumeDragAmount by remember { mutableStateOf(0f) }
    var initialVolume by remember { mutableStateOf(0f) }
    ...

How to fix?

  1. Consider not to wrap showControls and others into the remember { mutableStateOf(playerConfig.showControls) }
  2. Use remember(playerConfig.showControls) { mutableStateOf(playerConfig.showControls) } but this doesn't have a lot of sense, coz it won't decrease recompositions from my understanding. So, better just remove remember and allow code recompose every time when VideoPlayerConfig.showControls changed.

I wanted to contribute, submit PR. But didn't find where is library. I see the demo app only in the repo.
Anyway, thanks for this library, appreciate a lot!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions