Developed with 💙 by Very Good Ventures 🦄
A lightweight native video duration reader for Flutter that works on Android and iOS. No FFmpeg, no byte loading—just native platform APIs for fast, efficient video metadata extraction.
Generated by the Very Good CLI. 🤖
✅ Lightweight - Uses native platform APIs only (no FFmpeg dependencies)
✅ Fast - Reads metadata without loading video data into memory
✅ Cross-platform - Works on both Android and iOS
✅ Content URI support - Android content:// URIs supported
✅ Error handling - Returns Duration.zero on errors
✅ Type-safe - Returns Dart Duration object
| Platform | Implementation | Supported Paths |
|---|---|---|
| Android | MediaMetadataRetriever |
File paths, content:// URIs |
| iOS | AVURLAsset |
File paths, file:// URLs |
Add this to your package's pubspec.yaml file:
dependencies:
video_duration_native: ^0.1.0import 'package:video_duration_native/video_duration_native.dart';
// Get duration from a file path
final duration = await getDuration('/path/to/video.mp4');
print('Video duration: ${duration.inSeconds} seconds');
// Android content URI
final duration2 = await getDuration('content://media/external/video/123');
// Returns Duration.zero on error or invalid path
final invalid = await getDuration('/invalid/path.mp4');
print(invalid); // Duration: 0:00:00.000000import 'package:file_picker/file_picker.dart';
import 'package:video_duration_native/video_duration_native.dart';
Future<void> pickAndGetDuration() async {
final result = await FilePicker.platform.pickFiles(
type: FileType.video,
);
if (result != null && result.files.isNotEmpty) {
final path = result.files.first.path;
if (path != null) {
final duration = await getDuration(path);
print('Duration: ${duration.inSeconds} seconds');
print('Milliseconds: ${duration.inMilliseconds} ms');
}
}
}The Android implementation uses MediaMetadataRetriever to extract video metadata:
- Supports both file paths and content URIs
- Lightweight metadata extraction
- Automatic resource cleanup
- Returns duration in milliseconds
The iOS implementation uses AVURLAsset with optimized settings:
preloadsEligibleContentKeys = false- Avoids loading tracks into memoryprefersPreciseDurationAndTiming = true- Ensures accurate duration (iOS 13+)- Supports file paths and URLs
- Returns duration in milliseconds
This plugin uses Fluttium for integration tests. For detailed testing information, see TESTING.md.
# Run unit tests
cd video_duration_native
flutter test
# Run integration tests
cd video_duration_native/example
flutter test integration_test/app_test.dart
# Run Fluttium E2E tests
cd video_duration_native/example
fluttium test flows/test_platform_name.yaml
fluttium test flows/test_get_duration.yaml❗ To run Fluttium tests, you need fluttium_cli installed. See how.
The example app demonstrates all plugin features:
- Get platform name
- Pick video files using native file picker
- Get video duration with manual path input
- Display duration in seconds and milliseconds
cd video_duration_native/example
flutter runThis project uses release-please for automated version management and changelog generation. The workflow:
- Monitors commits to the
mainbranch - Automatically generates changelog entries based on conventional commits
- Creates release PRs when changes are ready
- Publishes releases to GitHub and pub.dev
Conventional Commits:
feat:- New features (minor version bump)fix:- Bug fixes (patch version bump)BREAKING CHANGE:- Breaking changes (major version bump)

