flutter_media_session 3.0.1
flutter_media_session: ^3.0.1 copied to clipboard
Sync media metadata and playback state with system controls on Android, iOS, macOS, Windows, and Web.
flutter_media_session #
A powerful Flutter plugin for integrating your app with system-level media controls (lock screen, notification, media center) across Android, iOS, macOS, Windows, and Web.
This plugin allows your app to display media metadata (title, artist, artwork) in the system's media center and respond to system actions like Play, Pause, Skip, and Seek.
Platform Support #
| Platform | Support | Underlying API |
|---|---|---|
| Available | Media3 MediaSessionService | |
| Available | MPNowPlayingInfoCenter / MPRemoteCommandCenter | |
| Available | SystemMediaTransportControls (SMTC) | |
| Planned | MPRIS | |
| Web | Available | Media Session API |
Features #
- 🧩 Professional Adapter Architecture: Decouple player implementations from system controls. Easily bind players using a unified
MediaSessionAdapterinterface without bloating the core package with third-party dependencies. - 🎵 Rich Metadata & Artwork Synchronization: Display titles, artists, album names, and artwork on system lock screens and media centers across all platforms.
- ⏯️ Precise Playback & Timeline Tracking: Synchronize playing/paused states, playback speed, and current elapsed position across all supported platforms.
- 📡 Bi-directional System Media Commands: Respond to standard system-level media controls, including Play, Pause, Stop, Seek, Skip Forward/Backward, Shuffle, and Repeat.
- 📶 Smart Background Keep-Alive: Maintain connection stability for off-device playback when the app is backgrounded using native platform keep-alive primitives.
- 🔈 Audio Focus Management (Optional): Built-in handling of audio focus interruptions for players that do not manage focus natively.
- 🎨 Custom Notification Actions (Android): Go beyond standard controls by adding custom actions with custom icons and labels directly inside the notification.
- 🎧 Out-of-the-Box Background Support (Android): Automatically manages foreground service requirements, notification lifecycles, and system notification permissions.
Installation #
Add flutter_media_session to your pubspec.yaml:
dependencies:
flutter_media_session: ^3.0.0
Setup #
Android, macOS & Web #
No configuration required.
iOS #
- Background Audio: Add the
audiobackground mode to yourInfo.plist:
This allows system-level controls to interact with your app in the background.<key>UIBackgroundModes</key> <array> <string>audio</string> </array>
Windows #
For proper application identification (avoiding the "Unknown Application" label in system controls), please refer to the:
Usage #
For detailed instructions and examples on how to initialize the plugin, manage media metadata, respond to system media events, and customize available media controls layout dynamically, please refer to our full breakdown:
License #
This project is licensed under the MIT License - see the LICENSE file for details.