Building an Android Video Player With Flutter and libVLC
Notes from building Peek, an open-source Android video player in Flutter and libVLC, covering codec choice, PiP, MediaSession, subtitles and 16KB page compliance.
A Flutter video player sounds like a weekend toy until you open a real folder of downloaded files. MKV containers, AC3 audio, two subtitle tracks, a 4K HEVC clip and an old AVI all sit next to each other, and the default plugin chokes on half of them.
I built Peek, an open-source Android video player, in a single day with Flutter and libVLC. This post covers the decisions that mattered: which playback engine to pick, how to wire picture-in-picture and lock-screen controls, how to handle subtitles and audio tracks, and the native library alignment problem that nearly blocked the build.
TL;DR
Use the official video_player package when you control the media (streaming MP4 or HLS from your own backend). Use a libVLC-based plugin when users bring their own files. Budget a little native Android code for picture-in-picture and MediaSession, and check that every native plugin you ship supports 16KB memory pages before you target modern devices.
key takeaways
- The stock video_player plugin is fine for streaming known formats, but local files with odd codecs need a libVLC-based engine.
- Picture-in-picture and lock-screen controls are native Android features, so plan a small amount of platform code from day one.
- Android's 16KB memory page requirement can break native plugins, and vendoring a compliant build is often the fastest fix.
- Resume position, history and gesture controls are what make a player feel finished, and they are cheap to build in Flutter.
Choosing the playback engine
The first decision shapes everything else. Flutter does not decode video itself; every option is a bridge to a native engine.
| Option | Engine underneath | Strengths | Weak spots |
|---|---|---|---|
| video_player (official) | ExoPlayer on Android, AVPlayer on iOS | Small, well maintained, great for HLS/MP4 | Limited container and codec coverage for local files |
| libVLC plugin | VLC's libVLC | Plays almost anything, embedded subtitle and audio tracks | Larger APK, native .so files to manage |
| media_kit style wrappers | libmpv | Wide format support, desktop friendly | Another native dependency chain to keep aligned |
For a player meant for a user's own files, codec coverage beats APK size. I went with libVLC because it reads embedded tracks directly, which means subtitle and audio switching come almost for free.
If you are building a course app or an OTT client where you encode the media yourself, the trade flips. Encode to H.264/AAC in HLS and use the official plugin. The video_player documentation on pub.dev covers that path well.
Native features you cannot skip on Android
A Flutter video player that stops when the user leaves the app feels broken. Two native features fix that.
Picture-in-picture
PiP is an activity-level feature. The steps I follow:
- Add
android:supportsPictureInPicture="true"and the rightconfigChangesto the main activity in the manifest. - Expose a method channel call such as
enterPip(aspectRatio)that buildsPictureInPictureParamswith the video's aspect ratio. - Trigger it on
onUserLeaveHintso pressing Home while playing drops into PiP automatically. - Listen for PiP mode changes on the Flutter side and hide controls, overlays and the app bar while in the small window.
The last step is the one people forget. If your controls stay visible, the PiP window shows a cramped toolbar instead of the video. The Android picture-in-picture guide explains the activity lifecycle details.
MediaSession and lock-screen controls
MediaSession is how Android shows play, pause and seek on the lock screen, in the notification shade and on Bluetooth headsets. Without it, headphone buttons do nothing. I register a session when playback starts, push metadata (title, duration) and map the callbacks back to the libVLC controller. Keep the playback state in one place in Dart so the lock screen, the in-app controls and the PiP window never disagree.
Subtitles, audio tracks and gestures
This is where libVLC pays for itself.
Subtitles. Embedded tracks in MKV files show up as a list from the engine. For external files, Peek loads SRT and VTT sidecars, either picked manually or matched by filename. A simple rule works: if movie.mkv sits next to movie.srt or movie.en.vtt, offer it automatically.
Audio tracks. Dual-audio files are common in the files people actually keep on their phones. The engine exposes track IDs and language tags, so the UI is a simple bottom sheet.
Gestures. Users expect the conventions from popular players:
- Horizontal drag to seek, with a preview of the target time.
- Vertical drag on the right half for volume, left half for brightness.
- Double-tap left or right to jump back or forward ten seconds.
- Pinch to switch between fit and fill.
Gesture code in Flutter is mostly a GestureDetector with careful thresholds so a seek drag does not also change volume. Lock the axis after the first few pixels of movement.
Resume and history. Store the last position per file path, plus a recent list. When a file opens, seek to the saved position if it is more than a few seconds in and not near the end.
The 16KB page size problem
Newer Android devices can run with 16KB memory pages instead of 4KB. Native libraries that were linked assuming 4KB alignment can fail to load on those devices, and Google Play is moving toward requiring 16KB support for apps that ship native code.
A video player is almost all native code underneath. The libVLC plugin I started with pulled in prebuilt .so files that were not aligned for 16KB pages. Waiting for an upstream release was not an option for a one-day build, so I vendored a 16KB-page-safe version of the plugin into the repo and pointed the pubspec at the local path.
My checklist for any Flutter app with native dependencies:
- List every plugin that ships
.sofiles (video, image processing, crypto, ML). - Check each one's changelog or issues for 16KB page support.
- Build a release APK and inspect alignment of the native libraries before shipping.
- Vendor or fork when upstream lags, and note the reason in the README so it gets revisited.
I also set min SDK 24, which keeps the device range wide without carrying very old API workarounds.
How I built this in practice
Peek is a real, open-source project: Flutter on top of libVLC, using the vendored 16KB-page-safe plugin, with picture-in-picture, MediaSession lock-screen controls, SRT/VTT subtitles, audio track switching, gesture controls, resume and history, and min SDK 24. The full write-up is in the Peek case study.
It went from empty repo to a usable app in a day because the scope was ruthless: no backend, no accounts, no casting. Every hour went into the things that make playback feel right: PiP that triggers on Home, headphone buttons that work, and files that resume where you left them.
The same approach carries into client apps. In Client Mitra I shipped Android and iOS apps through one Flutter wrapper with native sign-in, in-app purchase, push and Crashlytics added only where the platform demanded it. Flutter for the UI, small native pieces only where needed, is a pattern that keeps maintenance low.
Common mistakes
- Picking the official plugin for a local-files player, then discovering half the user's library will not play.
- Leaving overlays visible in picture-in-picture mode, so the small window shows controls instead of video.
- Skipping MediaSession, which makes Bluetooth and lock-screen buttons silently do nothing.
- Shipping native libraries without checking 16KB page alignment on newer devices.
- Letting seek and volume gestures fire together because the drag axis is never locked.
keep reading
FAQ
Which package should I use for a Flutter video player?+
For streaming common formats like MP4 and HLS, the official video_player package is enough. For local files with MKV containers, unusual audio codecs or embedded subtitle tracks, a libVLC-based plugin handles far more formats without extra work.
Does Flutter support picture-in-picture on Android?+
Not out of the box. You enable PiP in the Android manifest, call the platform API from a small method channel or plugin, and adjust your Flutter layout when the activity shrinks into the PiP window.
What is the Android 16KB page size issue?+
Newer Android devices can use 16KB memory pages, and native libraries compiled assuming 4KB alignment can fail to load. Any plugin shipping .so files needs builds aligned for 16KB pages, which is why I vendored a compliant libVLC plugin.
How long does it take to build a Flutter video player app?+
A focused player with PiP, subtitles, gestures and resume took me a day because the scope was tight and the engine was mature. A player with DRM, casting, downloads and a content backend is a multi-week project.
Devang Gandhi
AI & full stack developer at Passdn, building CRMs, SaaS, AI agents and Flutter apps for clients in the US, UK, Australia, UAE and India. More about me