Repository navigation
Flet-media-library — Media Library Access for Flet #6877
Replies: 2 comments
|
Nice! Seems like a pretty powerful library! 😃👍 I wish I had a project where I could fully test and use it. Also if you want some feedback make sure to repost this to Discord server or anything related, they'll close the issue and this message will be pretty much hidden in closed issues tab. |
Thanks! 😃 Really appreciate the feedback and the suggestion. I’ll share it with the Flet Discord/community as well so it can reach more people who are building mobile apps with Flet and hopefully get some real-world feedback. Thanks again for taking the time to check it out! 👍 |
Uh oh!
There was an error while loading. Please reload this page.
Hi @FeodorFitsner @ndonkoHenri @xzripper
I would like to share a new open-source Flet service extension for working with the device media library from Python:
flet-media-libraryGitHub: https://github.com/fazi-gondal/Flet-media-library
PyPI: https://pypi.org/project/flet-media-library/
Latest version: 1.1.2
License: MIT
Platforms: Android & iOS
Requires: Flet >= 1.0.0
What is it?
flet-media-libraryprovides a Flet-native Python API for accessing and managing photos, videos, and audio in the device media library.It is designed for applications such as:
The package uses Flutter's
photo_managerfor cross-platform media-library functionality and adds custom native Android Kotlin functionality where the upstream package does not provide the required APIs.Main Features
Pictures/orDCIM/Movies/orDCIM/Music/on AndroidAndroid Permission Model
The package follows the least-privilege approach and does not require
MANAGE_EXTERNAL_STORAGE.It handles:
READ_EXTERNAL_STORAGEREAD_MEDIA_IMAGESREAD_MEDIA_VIDEOREAD_MEDIA_AUDIOREAD_MEDIA_VISUAL_USER_SELECTEDThis allows applications to request only the media types they actually need.
iOS
The package integrates with PhotoKit and supports:
Android-only operations such as audio saving, renaming and moving are reported through the API as unsupported on iOS instead of silently failing.
Native Android Extensions
One of the goals of this package is to fill gaps that are not currently covered by
photo_manager.Custom Kotlin implementations provide:
MediaStore.AudioMediaStore.RELATIVE_PATHThis means applications can work with the public media library without requiring unrestricted filesystem access.
Thumbnail Performance
Two thumbnail APIs are available:
for simple Base64-based usage, and:
for larger galleries.
get_thumbnail_path()writes the thumbnail to a local cache and returns its filesystem path, avoiding repeated Base64 transfers between Python and the Flutter/Dart layer.This is particularly useful for scrolling gallery grids containing hundreds or thousands of assets.
Permissions API
Permissions can be queried and requested independently:
Applications can therefore build their UI around the actual permission state instead of assuming that all media access was granted.
Media Queries
Media can be queried with:
Supported filtering/sorting includes:
The returned
MediaAssetPageprovides:itemstotaloffsetlimithas_moreSaving Media
Images:
Videos:
Android audio:
relative_pathis the preferred destination argument, whilealbumremains available as a backward-compatible alias.Media Management
The package also provides:
Platform differences are exposed through
UnsupportedErrorand capability detection.Change Notifications
Applications can monitor the device media library:
This allows applications to react when media is added, removed, or modified instead of constantly polling the library.
Capability Detection
Applications can inspect the current platform:
Capabilities include:
supports_audio_savesupports_movesupports_renamesupports_copysupports_mime_filtersupports_limited_accesssupports_thumbnail_pathsupports_change_notifyThis makes it possible to write platform-aware applications without hard-coding assumptions.
Quick Start
Then:
Demo Application
The repository also includes a full demo application with:
A pre-built Android demo APK is available from GitHub Releases:
https://github.com/fazi-gondal/Flet-media-library/releases
Why I am sharing this here
Flet makes it possible to build mobile applications primarily with Python, but mobile applications often need platform-specific capabilities that are outside the normal UI layer.
Media-library access is one of those areas.
This package is intended to provide a reusable Flet service instead of every Flet application having to implement its own Android/iOS media-library integration.
I would love to get feedback from the Flet community about:
Repository: https://github.com/fazi-gondal/Flet-media-library
All reactions