YoutubeKit
YoutubeKit copied to clipboard
Help Needed - How to optimize performance for frequent loading
I am currently creating an app that scrolls Youtube Videos like Tiktok.
I am using TableView for horizontal scrolling. My code looks something like below and it works as expected, just that it doesn't seem to be enough. Each cell would have its own Youtube Video (which loads successfully due to this great library), but there is "accumulating" impact to the memory.
What I mean is that, the more scrolling the user does, the higher memory needed, and eventually it affects the performance/scrolling, etc.
So I tried to write a piece of code to .clearVideo() everytime, the video is out of visible area of the phone. But for some reason, it doesn't work and I am not able to look into evaluatePlayerCommand function.
Could you please let me know how I can completely "remove" initially loaded Youtube Video, so it will not impact the memory performance?
let visibleRows = activeExerciseTableView.indexPathsForVisibleRows
if let visibleRows = visibleRows {
visibleRows.forEach { indexPath in
if let cell = activeExerciseTableView.cellForRow(at: indexPath) as? ActiveExerciseTableViewCell, activeExerciseTableView.bounds.contains(cell.frame) {
for (index, setViewModel) in cellExercise.sets.enumerated() {
if indexPath.row != index {
setViewModel.shouldPlayVideo = false
cell.ytVideoPlayer.clearVideo()
}
else if indexPath.row == index {
setViewModel.shouldPlayVideo = true
cell.ytVideoPlayer.playVideo()
}
}