8000 Transparent view sometimes when play video with Jetpack Compose · Issue #2304 · androidx/media · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Transparent view sometimes when play video with Jetpack Compose #2304

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

Closed
1 task
GazimSoliev opened this issue Apr 3, 2025 · 4 comments
Closed
1 task

Transparent view sometimes when play video with Jetpack Compose #2304

GazimSoliev opened this issue Apr 3, 2025 · 4 comments
Assignees

Comments

@GazimSoliev
Copy link

Version

Media3 1.6.0

More version details

I got transparent view when play video in Jetpack Compose sometimes

Devices that reproduce the issue

Samsung SM-X210 Android 14.0

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Not tested

Reproduction steps

It's hard to reproduce, but it happens when I change between video and different composable component.

But I have a code of video player in compose

fun VideoPlayerInternal(
    modifier: Modifier,
    uri: String,
    onFinished: () -> Unit,
    videoStatus: VideoStatus,
    muted: Boolean,
) {
    val context = LocalContext.current
    val player = remember { ExoPlayer.Builder(context).build() }
    LaunchedEffect(Unit) {
        player.addListener(
            object : Player.Listener {
                override fun onPlaybackStateChanged(playbackState: Int) {
                    if (playbackState == Player.STATE_ENDED) onFinished()
                }
            },
        )
    }
    LaunchedEffect(muted) {
        player.volume = if (muted) 0f else 1f
    }
    LaunchedEffect(uri) {
        val mediaItem = MediaItem.fromUri(uri)
        player.setMediaItem(mediaItem)
        player.prepare()
    }
    LaunchedEffect(videoStatus) {
        when (videoStatus) {
            VideoStatus.Playing -> player.play()
            VideoStatus.Paused -> player.pause()
        }
    }
    AndroidView(
        modifier = modifier,
        factory = {
            val view = PlayerView(it)
            view.setEnableComposeSurfaceSyncWorkaround(true)
            view.useController = false
            view.player = player
            view
        },
        
            player.release()
        },
    )
}

Expected result

Play videos without transparent view

Actual result

Videos play with transparent view

Media

Any video, loaded from file system

Bug Report

@GazimSoliev
Copy link
Author

I have found temporary fix, to set player in player view with delay 100 milliseconds:

fun VideoPlayerInternal(
    modifier: Modifier,
    uri: String,
    onFinished: () -> Unit,
    videoStatus: VideoStatus,
    muted: Boolean,
) {
    val context = LocalContext.current
    val player = remember { ExoPlayer.Builder(context).build() }
    val scope = rememberCoroutineScope()
    LaunchedEffect(Unit) {
        player.addListener(
            object : Player.Listener {
                override fun onPlaybackStateChanged(playbackState: Int) {
                    if (playbackState == Player.STATE_ENDED) onFinished()
                }
            },
        )
    }
    LaunchedEffect(muted) {
        player.volume = if (muted) 0f else 1f
    }
    LaunchedEffect(uri) {
        val mediaItem = MediaItem.fromUri(uri)
        player.setMediaItem(mediaItem)
        player.prepare()
    }
    LaunchedEffect(videoStatus) {
        when (videoStatus) {
            VideoStatus.Playing -> player.play()
            VideoStatus.Paused -> player.pause()
        }
    }
    AndroidView(
        modifier = modifier,
        factory = {
            val view = PlayerView(it)
            view.setEnableComposeSurfaceSyncWorkaround(true)
            view.useController = false
            scope.launch {
                // Delay for fix a bug with transparent video
                delay(100)
                view.player = player
            }
            view
        },
        
            player.release()
        },
    )
}

@tonihei
Copy link
Collaborator
tonihei commented Apr 4, 2025

I copied your original snippet without the delay in a sample app and can't observe any issues. I'm also not sure how a "transparent view" would look like in this case. Is there no video at all or something else?

For the type of integration you are using, I'd would also recommend to use the Compose utils for playback in Media3. PlayerView within Compose isn't fully supported at the moment.

@google-oss-bot
Copy link
Collaborator

Hey @GazimSoliev. We need more information to resolve this issue but there hasn't been an update in 14 weekdays. I'm marking the issue as stale and if there are no new updates in the next 7 days I will close it automatically.

If you have more information that will help us get to the bottom of this, just add a comment!

@google-oss-bot
Copy link
Collaborator

Since there haven't been any recent updates here, I am going to close this issue.

@GazimSoliev if you're still experiencing this problem and want to continue the discussion just leave a comment here and we are happy to re-open this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants
0