Flutter Video Player disposing video

861 views
Skip to first unread message

Huzeyfe Coşkun

unread,
Sep 17, 2019, 3:00:22 PM9/17/19
to Flutter Development (flutter-dev)
Hi there,
i am making app like instagram. 
I am having issues with video player. I am loading posts in to listview but when video player
not visible its disposing video then re loading.

i didnt find a good solution for loading videos. smooth and onetime

Kyle Bedell

unread,
Sep 17, 2019, 9:07:26 PM9/17/19
to Flutter Development (flutter-dev)
ListViews are virtualized, they dispose of and rebuild their unviewable items to recycle memory. Consider caching the video playback position in a Map<string, int> to look up the last playback position of the video when the widget rebuilds. You can pass in the position from the builder callback. Keeping the videos around would be like having a memory leak as the user scrolls past 10s or 100s of videos. Your videos are likely to have UUIDs assigned at upload time, use that for the string of the hash map. The int is obviously going to be the time in seconds.

You can get the position from the VideoPlayerController.

https://pub.dev/documentation/video_player/latest/video_player/VideoPlayerController/position.html

Reply all
Reply to author
Forward
0 new messages