Pinterest Grey Skold Nov 15, 2022

Improving the Player on Android

Article Summary

Pinterest's Android team faced a unique challenge: playing multiple videos simultaneously in a two-column grid without killing performance. Here's how they optimized ExoPlayer to handle it.

The Pinterest Engineering team shares their deep dive into video player optimization for Android. They tackled startup latency, memory management, and bandwidth issues specific to their mixed-media feed experience.

Key Takeaways

Critical Insight

By customizing ExoPlayer's DefaultLoadControl, DefaultTrackSelector, and building a smart player pool, Pinterest significantly reduced video startup latency while managing memory constraints.

The article reveals a critical mistake most apps make with ExoPlayer's setForegroundMode flag and when you should actually use it.

About This Article

Problem

Pinterest's video player was slow to start because ExoPlayer was doing extra work. It kept calculating aspect ratios and triggering layout callbacks even though the video dimensions were already known.

Solution

The team set aspect ratios upfront using AspectRatioFrameLayout.setAspectRatio(). They also overrode PlayerView.onContentAspectRatioChanged() with an empty implementation to stop unnecessary recalculations.

Impact

Removing this redundant UI rendering work reduced video startup latency at Pinterest. The fix didn't require any changes to ExoPlayer itself.