A high-performance Android app that implements a vertical swipe video player similar to Facebook Reels using ViewPager2, ExoPlayer (Media3), and ViewModel for seamless playback state retention.
✅ ViewPager2 + FragmentStateAdapter → Smooth vertical swipe experience
✅ ExoPlayer (Media3) → High-performance video playback
✅ ViewModel for Playback State → Resumes video when swiping back
✅ Efficient Memory Management → Only one ExoPlayer runs at a time
✅ Optimized Performance → Prevents memory leaks and excessive player instances
- Kotlin
- ViewPager2 (for swipe functionality)
- ExoPlayer (Media3) (for video playback)
- ViewModel (for retaining playback state)
📂 app
┣ 📜 MainActivity.kt → Sets up ViewPager2
┣ 📜 FragmentVideo.kt → Handles ExoPlayer instance per page
┣ 📜 PagerAdapterVideo.kt → Adapter for ViewPager2
┣ 📜 ViewModelMain.kt → Stores playback positions
┣ 📜 ViewModelVideo.kt → Handle Exoplayer
Scrolling Experience

Video Playback
vid_swipe_exo_player.mp4
- Clone the repo
git clone https://github.com/epegasus/SwipeExoPlayer.git
- Open in Android Studio
- Run the project on an emulator or device
- The ViewPager2 loads
VideoFragment
for each video. - Each fragment initializes ExoPlayer in
onViewCreated()
. - The ViewModel stores playback position and restores it when swiping back.
- The app ensures only one ExoPlayer instance plays at a time to optimize memory usage.
Feel free to fork, improve, and submit PRs to enhance this project!
This project is licensed under the MIT License.