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

YASAN

12/04/2021, 1:33 PM
I use
compose-navigation
. I have a relatively heavy video player route which can be opened from a few other routes. Is there a way to always keep that route open in the background so it doesn't have to initialize every time? I just want to change the
videoId
used in the route every time its opened.
1
👋 1
This route's composable contains a video player object which takes ~5s to initialize fully and since its a video player app, its really annoying for the user to wait that time every time they want to watch another video.
i

Ian Lake

12/04/2021, 10:48 PM
Sounds like a good candidate to hoist that expensive object up outside of your NavHost i.e., a VideoPlayerCache object that would reuse a video player instance upon request
🙌 1
👀 1
c

Colton Idle

12/05/2021, 2:52 AM
I had to do something like this and basically just made it the background of my NavHost and just always kept it around. It was for a POC app, but that ended up working pretty well. If I wanted to show the video then I would just hit the playMethod and turn the background transparent of my current screen, which would show the background video. I was basically trying to do something like what spotify had a while back.
👀 1
🙌 1
y

YASAN

12/05/2021, 5:25 AM
Okay thank you 🤔 Ill try what I can do.
3 Views