A comprehensive Flutter video player plugin with advanced features including video playback, download capabilities, and screen protection.
- Multi-source support: Play videos from URLs, assets, and downloaded files
- Quality selection: Multiple resolution options with automatic quality detection
- Playback controls: Play, pause, seek, and speed control
- Fullscreen support: Native fullscreen video playback experience
- Screenshot prevention: Prevent screenshots during video playback
- Screen recording detection: Detect and handle screen recording attempts
- Secure playback: Enhanced content protection for sensitive videos
- iOS: Full native implementation with AVPlayer and AVKit
- Android: Native Android implementation
- Flutter integration: Seamless integration with Flutter widgets
Add this to your package's pubspec.yaml file:
dependencies:
video_player: ^2.0.0Add the following to your ios/Runner/Info.plist:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>For background downloads, ensure your app supports background modes in Info.plist:
<key>UIBackgroundModes</key>
<array>
<string>background-processing</string>
<string>background-fetch</string>
</array>import 'package:video_player/video_player.dart';
// Play a video from URL
VideoPlayer.playVideo(PlayerConfiguration(
title: 'Sample Video',
videoUrl: 'https://example.com/video.mp4',
qualityText: 'Quality',
speedText: 'Speed',
autoText: 'Auto',
playVideoFromAsset: false,
assetPath: '',
lastPosition: 0,
movieShareLink: 'https://example.com/share',
));// Start download
VideoPlayer.downloadVideo(DownloadConfiguration(
url: 'https://example.com/video.m3u8',
title: 'My Video',
));
// Monitor download progress
VideoPlayer.onDownloadProgress.listen((progress) {
print('Download progress: ${progress.percent}%');
print('Downloaded bytes: ${progress.downloadedBytes}');
print('Download state: ${progress.state}');
});
// Pause download
VideoPlayer.pauseDownload(downloadConfig);
// Resume download
VideoPlayer.resumeDownload(downloadConfig);
// Check if video is downloaded
bool isDownloaded = await VideoPlayer.checkIsDownloadedVideo(downloadConfig);VideoPlayerView(
url: 'https://example.com/video.mp4',
resizeMode: ResizeMode.fit, // ResizeMode.fit, ResizeMode.fill, or ResizeMode.zoom
onMapViewCreated: (controller) {
// Video player created, save the controller for later use
this.controller = controller;
// Listen to position updates
controller.positionStream.listen((position) {
print('Current position: $position seconds');
});
// Get notified when duration is ready
controller.onDurationReady((duration) {
print('Video duration: $duration seconds');
});
},
)// Play the video
await controller.play();
// Pause the video
await controller.pause();
// Mute audio
await controller.mute();
// Unmute audio
await controller.unmute();
// Get video duration
double duration = await controller.getDuration();
// Seek to a specific position (in seconds)
await controller.seekTo(30.0); // Seek to 30 seconds
// Change video URL
await controller.setUrl(url: 'https://example.com/new-video.mp4');
// Load video from assets
await controller.setAssets(assets: 'assets/videos/my_video.mp4');The iOS implementation uses native iOS components for optimal performance:
- UIActivityIndicatorView: Native loading indicators for video buffering and loading states
- AVPlayer & AVKit: Core video playback functionality
- Native gestures: Swipe for volume/brightness, tap to play/pause, double-tap to seek
The iOS implementation includes ScreenProtectorKit for content protection:
// In your AppDelegate.swift
import video_player
class AppDelegate: FlutterAppDelegate {
private var screenProtectorKit: ScreenProtectorKit?
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
screenProtectorKit = ScreenProtectorKit(window: window)
screenProtectorKit?.configurePreventionScreenshot()
// Setup screenshot detection
screenProtectorKit?.screenshotObserver {
print("Screenshot detected!")
// Handle screenshot event
}
// Setup screen recording detection (iOS 11.0+)
if #available(iOS 11.0, *) {
screenProtectorKit?.screenRecordObserver { isCaptured in
print("Screen recording: \(isCaptured)")
// Handle screen recording state change
}
}
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
override func applicationDidBecomeActive(_ application: UIApplication) {
screenProtectorKit?.enabledPreventScreenshot()
}
override func applicationWillResignActive(_ application: UIApplication) {
screenProtectorKit?.disablePreventScreenshot()
}
}The plugin automatically sorts video resolutions and provides quality selection UI during playback.
iOS implementation uses AVAssetDownloadURLSession for reliable background downloads that continue even when the app is backgrounded.
- HLS (HTTP Live Streaming) support with content protection
- DRM-protected content playback (when supported by source)
- Secure storage of downloaded content
title: Video titleinitialResolution: Initial quality selectionresolutions: Available quality optionsqualityText: Text for quality selection buttonspeedText: Text for speed selection buttonautoText: Text for auto quality optionplayVideoFromAsset: Whether to play from app assetsassetPath: Asset file path (if playing from assets)lastPosition: Resume position in secondsmovieShareLink: Share URL for the video
- iOS: 15.0+
- Flutter: 3.32.0+
- Dart: 3.8.0+
Third-party Libraries:
- TinyConstraints: Auto Layout DSL for Swift
- XLActionController: Customizable action sheets
- SnapKit (~> 4.0): Swift Auto Layout DSL
- SDWebImage (~> 5.0): Image loading and caching
Native iOS Frameworks:
- UIKit: For native UI components (UIActivityIndicatorView, etc.)
- AVFoundation: Core video playback engine
- AVKit: Advanced video playback features and Picture-in-Picture
- MediaPlayer: Volume controls and media information
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the MIT License - see the LICENSE file for details.