wistia_enforce 1.0.0
wistia_enforce: ^1.0.0 copied to clipboard
A Flutter video player for Wistia that enforces watch time. Features include progress tracking, resume functionality, and callbacks for saving user progress.
Wistia Enforce Player #
A Flutter video player designed for Wistia that enforces watch time. This package is ideal for educational content, compliance training, or any application where you need to ensure users watch a certain amount of a video before proceeding.
It is built on top of the excellent better_player_plus package and provides a simple, clean API for a powerful feature set.
Features #
- Watch Time Enforcement: Prevent users from seeking forward past their watched progress.
- Progress Tracking: Keep track of how many seconds of a video a user has watched.
- Backend Updates: Provides periodic callbacks to save user progress to your server.
- Resume Functionality: Prompts users to resume from where they left off.
- Error Handling: Exposes errors for custom handling and UI.
- Dynamic Aspect Ratio: Automatically adjusts the player's aspect ratio to match the video's dimensions.
- Flexible Configuration: Easily configure enforcement rules, progress update intervals, and more.
Getting Started #
Prerequisites #
This package requires a Wistia account and a mediaId for the video you wish to play.
Installation #
Add this to your package's pubspec.yaml file:
dependencies:
wistia_enforce: ^1.0.0
Then, run flutter pub get in your terminal.
Usage #
Import the package and use the WistiaEnforcePlayer widget in your app.
import 'package:wistia_enforce/wistia_enforce.dart';
class MyVideoScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Wistia Player'),
),
body: Center(
child: WistiaEnforcePlayer(
mediaId: 'your_wistia_media_id',
stopSeeking: true,
requiredWatchTime: 60, // Enforce 60 seconds of watch time
previouslyWatchedTime: 20, // User has already watched 20 seconds
onProgress: (remainingTime, isEnforcementMet) {
print('Remaining time: $remainingTime, Enforcement met: $isEnforcementMet');
},
onProgressUpdate: (secondsWatched) async {
print('User watched another $secondsWatched seconds. Saving to backend...');
// await myApi.saveProgress(secondsWatched);
},
onEnforcementTimeReached: () {
print('User has met the required watch time!');
},
onError: (error) {
print('An error occurred: $error');
},
),
),
);
}
}
Available Parameters #
| Parameter | Type | Description |
|---|---|---|
mediaId |
String |
Required. The unique identifier for the Wistia media. |
stopSeeking |
bool |
Determines if playback restrictions are active. If true, seeking forward is disabled until the required watch time is met. Defaults to false. |
requiredWatchTime |
double |
The minimum time in seconds the user must watch the video. Defaults to 0. |
previouslyWatchedTime |
double |
The number of seconds the user has already watched. This is used to resume progress. Defaults to 0. |
progressUpdateInterval |
int |
The interval in seconds for the onProgressUpdate callback. Defaults to 5. |
onProgress |
Function(int, bool) |
A callback that fires periodically as the video plays. Provides the remaining time to watch and whether the enforcement condition is met. |
onProgressUpdate |
Future<void> Function(int) |
A callback that fires at progressUpdateInterval of new watch time. Use this to save the user's progress to a backend. |
onEnforcementTimeReached |
VoidCallback |
A callback that fires once when the requiredWatchTime has been reached. |
onError |
Function(String) |
A callback for handling exceptions during video fetching or playback. |
Additional Information #
-
How does
stopSeekingwork? WhenstopSeekingistrue, the player tracks the furthest point the user has watched (theseekableHeadSeconds). If the user tries to seek past this point, the player will automatically seek back. This ensures they cannot skip content. -
How is progress tracked with
previouslyWatchedTime? When the widget initializes, it can start with apreviouslyWatchedTime. If this time is greater than 0 and less than therequiredWatchTime, the user will be prompted to either resume from where they left off or start over. -
When should I use
onProgressUpdate? TheonProgressUpdatecallback is designed for saving progress to a backend. It fires at a configurable interval of newly watched time, so you don't have to worry about overwhelming your server with requests.
If you have any issues or feature requests, please file them in the GitHub repository.