https://kotlinlang.org logo
#compose
Title
# compose
h

Halil Ozercan

08/25/2020, 2:50 PM
Lately, I've been trying to implement a reddit client in compose. The first challenge I wanted to take on was to play gifs and videos in a list. Notoriously Recyclerview that present video content has been a difficult problem. However, I thought compose would be different based on the experience from my first Youtube like Video Player project. This required a lot more optimization than I initially anticipated but I think this is close to something usable 🙂
👍 4
❤️ 2
p

ppvi

08/25/2020, 3:34 PM
can you talk about the optimizations that it required?
h

Halil Ozercan

08/25/2020, 4:10 PM
Most of these are not optimizations but instead weird implementation details to achieve what I wanted. Sorry if there was a confusion. First of all I started with the video player that I created for my previous project. While designing it, there was no requirement for it to be constantly disposed and recreated. That's why I needed to make adjustments on that end.
rememberSavedInstanceState
didn't work as I expected. I assumed it was going to hold on to the state as long as the composition didn't change order. However,
LazyColumnFor
items are not able to preserve their state by using
rememberSavedInstanceState
, maybe I did something wrong? If I were to directly put
VideoPlayer
composable in each item, it produced a high amount of lag. Scrolling dropped the FPS to almost 1~2. Instead, I had to use
launchInComposition
to delay the actual composition while adding a placeholder with the same size. Also ExoPlayer used a lot of memory initially, so I had many experiments to solve that but it isn't really related to Compose. Since
LazyColumnFor
still does not share its scroll state, I had to use
onPositioned
to understand which item entered the view or left. I don't think it is the best option but it helped me to write a
Coordinator
to manage which video should be played at any given scroll state.
a

Andrey Kulikov

08/25/2020, 4:18 PM
rememberSavedInstanceState persistence in LazyColumnFor is not yet ready, but is planned
h

Halil Ozercan

08/25/2020, 4:20 PM
@Andrey Kulikov that's good to know 👍
5 Views