Chris Grigg
03/19/2021, 3:29 PMAndroidView
and I need to set a layout attribute as described at https://exoplayer.dev/ui-components.html#choosing-a-surface-type. I’m having trouble finding how I should do this. Could someone point me in the right direction? I’m going to add a small code snippet in a reply below.Chris Grigg
03/19/2021, 3:30 PMAndroidView(
modifier = Modifier.padding(0.dp, 0.dp, 32.dp, 0.dp),
factory = { viewBlockContext ->
PlayerView(viewBlockContext).apply {
hideController()
useController = false
resizeMode = AspectRatioFrameLayout.RESIZE_MODE_FIT
player = exoPlayer
layoutParams = LinearLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
setKeepContentOnPlayerReset(true)
setShutterBackgroundColor(android.graphics.Color.WHITE)
exoPlayer.repeatMode = Player.REPEAT_MODE_ALL
}
}
)
Chris Grigg
03/19/2021, 3:30 PMPlayerView
is initialized?Adam Powell
03/19/2021, 3:33 PMLayoutParams
on the view returned by the AndroidView
factory don't matter, compose uses the modifier applied to the AndroidView
composable to determine how the view should be measuredAdam Powell
03/19/2021, 3:34 PM.fillMaxSize()
after your paddingAdam Powell
03/19/2021, 3:34 PMAdam Powell
03/19/2021, 3:38 PMAttributeSet
is not subclassable by apps so you won't be able to fake it that way.Adam Powell
03/19/2021, 3:38 PMAdam Powell
03/19/2021, 3:40 PMLayoutInflater.from(context)
dance in the factory block or use AndroidViewBinding
+ viewbinding instead; the latter is nicer for usability but if this is the only place you're using it, setting it all up is probably overkillChris Grigg
03/19/2021, 3:40 PMChris Grigg
03/19/2021, 3:42 PMChris Grigg
03/19/2021, 3:42 PMLayoutInflater.from(context)
is probably the way to goChris Grigg
03/19/2021, 3:44 PMAdam Powell
03/19/2021, 3:44 PMlayoutInflater.inflate(<http://R.layout.my|R.layout.my>_layout_file, null)
Adam Powell
03/19/2021, 3:45 PMnull
being the ViewGroup
parent parameterChris Grigg
03/19/2021, 3:45 PMChris Grigg
03/19/2021, 3:46 PMlayoutInflater
called when using AndroidView
in compose? You mentioned the factory block, so would it be before I call PlayerView
?Cyril Find
03/19/2021, 3:54 PMAndroidView(
factory = { PlayerView(context).apply {
keepScreenOn = true
useController = false
}
})
Chris Grigg
03/19/2021, 3:55 PMChris Grigg
03/19/2021, 3:56 PMChris Grigg
03/19/2021, 3:56 PMCyril Find
03/19/2021, 3:57 PMChris Grigg
03/19/2021, 4:00 PMChris Grigg
03/19/2021, 4:01 PMChris Grigg
03/19/2021, 4:02 PMAndroidView(
modifier = Modifier.padding(0.dp, 0.dp, 32.dp, 0.dp),
factory = { viewBlockContext ->
var output: PlayerView? = null
LayoutInflater.from(viewBlockContext).apply {
(inflate(R.layout.exercise_video_view, null) as PlayerView).apply {
hideController()
player = exoPlayer
output = this
}
}
output!!
}
)
Chris Grigg
03/19/2021, 4:02 PMoutput
var seems grossCyril Find
03/19/2021, 4:03 PMapply
?Chris Grigg
03/19/2021, 4:05 PMChris Grigg
03/19/2021, 4:05 PMChris Grigg
03/19/2021, 4:06 PMChris Grigg
03/19/2021, 4:07 PMChris Grigg
03/19/2021, 4:07 PMChris Grigg
03/19/2021, 4:07 PM<?xml version="1.0" encoding="utf-8"?>
<com.google.android.exoplayer2.ui.PlayerView xmlns:android="<http://schemas.android.com/apk/res/android>"
xmlns:app="<http://schemas.android.com/apk/res-auto>"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:keep_content_on_player_reset="true"
app:repeat_toggle_modes="all"
app:shutter_background_color="@color/white"
app:surface_type="texture_view"
app:use_controller="false">
</com.google.android.exoplayer2.ui.PlayerView>
Chris Grigg
03/19/2021, 4:07 PMChris Grigg
03/19/2021, 4:07 PMAndroidView(
modifier = Modifier.padding(0.dp, 0.dp, 32.dp, 0.dp),
factory = { viewBlockContext ->
val inflater = LayoutInflater.from(viewBlockContext)
(inflater.inflate(R.layout.exercise_video_view, null) as PlayerView).apply {
scaleX = if (mirrored) -1f else 1f
hideController()
player = exoPlayer
}
}
)
Chris Grigg
03/19/2021, 4:08 PM