@@ -47,6 +47,7 @@ import androidx.core.content.ContextCompat
47
47
import androidx.core.graphics.toRect
48
48
import androidx.core.util.Consumer
49
49
import androidx.media3.common.Player
50
+ import androidx.media3.common.VideoSize
50
51
import androidx.media3.exoplayer.ExoPlayer
51
52
52
53
var shouldEnterPipMode by mutableStateOf(false )
@@ -237,6 +238,7 @@ fun PiPBuilderSetSourceRect(
237
238
238
239
@Composable
239
240
fun PiPBuilderSetAspectRatio (
241
+ player : Player ? ,
240
242
shouldEnterPipMode : Boolean ,
241
243
modifier : Modifier = Modifier ,
242
244
) {
@@ -246,12 +248,11 @@ fun PiPBuilderSetAspectRatio(
246
248
247
249
val pipModifier = modifier.onGloballyPositioned { layoutCoordinates ->
248
250
val builder = PictureInPictureParams .Builder ()
249
-
250
- if (shouldEnterPipMode) {
251
+ if (shouldEnterPipMode && player != null && player.videoSize != VideoSize .UNKNOWN ) {
251
252
val sourceRect = layoutCoordinates.boundsInWindow().toAndroidRectF().toRect()
252
253
builder.setSourceRectHint(sourceRect)
253
254
builder.setAspectRatio(
254
- Rational (sourceRect. width(), sourceRect. height() )
255
+ Rational (player.videoSize. width, player.videoSize. height)
255
256
)
256
257
}
257
258
@@ -312,6 +313,7 @@ fun listOfRemoteActions(): List<RemoteAction> {
312
313
313
314
@Composable
314
315
fun PiPBuilderAddRemoteActions (
316
+ player : Player ? ,
315
317
shouldEnterPipMode : Boolean ,
316
318
modifier : Modifier = Modifier ,
317
319
) {
@@ -325,11 +327,11 @@ fun PiPBuilderAddRemoteActions(
325
327
listOfRemoteActions()
326
328
)
327
329
328
- if (shouldEnterPipMode) {
330
+ if (shouldEnterPipMode && player != null && player.videoSize != VideoSize . UNKNOWN ) {
329
331
val sourceRect = layoutCoordinates.boundsInWindow().toAndroidRectF().toRect()
330
332
builder.setSourceRectHint(sourceRect)
331
333
builder.setAspectRatio(
332
- Rational (sourceRect. width(), sourceRect. height() )
334
+ Rational (player.videoSize. width, player.videoSize. height)
333
335
)
334
336
}
335
337
0 commit comments