Is there a purely Compose way to play Video? I see a lot of people use AndroidView to use the ExoPlayer or some other android Surface class stuff. Is there no 'compose' way?
a
Adam Powell
03/10/2021, 9:09 PM
"purely" compose APIs for this will likely take the form of wrappers around the AndroidView approaches to put a nice API surface around it for the time being
z
Zach Klippenstein (he/him) [MOD]
03/10/2021, 9:12 PM
What would “pure” compose mean here? Any video player is probably going to end up talking to a surface at some level, whether it uses android views or some compose api to get the surface. Both Android views and Compose generally operate at a higher level than raw surfaces for most of their drawing, so either way you’d need a way to punch through that.
j
jaqxues
03/10/2021, 9:14 PM
Alright thanks, will use that then
h
Halil Ozercan
03/10/2021, 9:15 PM
Are you asking for a built-in composable that plays video or any other way other than using AndroidView? For the former, no afaik. Answer to the second question would be a bit more loaded.
Playing a video in a purely declarative way is a weird goal. Video is akin to graphics rendering more than a traditional UI. In graphic rendering, all you need is a surface that serves you a real estate on the screen. A
MediaPlayer
,
VideoPlayer
, or
ExoPlayer
has access to this surface to draw its state(picture). Using compose to do the drawing would just be flipping the dependencies and not a great one at that. VideoPlayers like ExoPlayer have years of experience in optimizing for rendering.
ps; the topic was closed until I wrote this but didn't want to delete my rumbling 🙂
e
ephemient
03/10/2021, 9:16 PM
right, ideally hardware decodes the video directly to the surface for display. Compose or not, you want to get the CPU out of the way of that path as much as possible
a
Adam Powell
03/10/2021, 9:26 PM
I certainly wouldn't mind a future API to skip SurfaceView and go straight to a Surface managed by Compose, but we have no short-term plans to provide such a thing.