green_video 2.0.33
green_video: ^2.0.33 copied to clipboard
Green Video Player Flutter plugin.
green_video #
Green Video Player for Flutter
Getting Started #
- Import the green_video dependency in your pubspec.yaml
dependencies:
green_video: <version>
- import the player widget
import 'package:green_video/widgets/green_video.dart';
- use the Flutter GreenVideo Player widget in your app
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Example app'),
),
body: Column(
children: [
const SizedBox(height: 100),
GreenVideo(
width: 400,
height: 240,
licenseKey: "LICENSE_KEY",
embedId: "EMBED_ID",
contentId: "CONTENT_ID",
controller: /* a green video controller instance */,
),
],
),
),
);
}
- Handle player events using the GreenVideoController
final controller = GreenVideoController();
controller.playerEvents.listen((event) {
if (event is OnPlayEvent) {
print("Player started playing");
} else if (event is OnPauseEvent) {
print("Player paused");
} else if (event is OnSeekEvent) {
print("Player seeked to position ${event.position}");
}
});
- Control the player using the GreenVideoController
controller.execute(PlayCommand()); // Start playing
controller.execute(PauseCommand()); // Pause the player
controller.execute(SeekCommand(30.0)); // Seek to 30 seconds
Getting Started
Player Commands #
The GreenVideoController provides the following commands to control the player:
- PlayCommand(): Start playing the video.
- PauseCommand(): Pause the video.
- SeekCommand(position): Seek to a specific position in the video (in seconds).
- MuteCommand(): Mute the video.
- UnmuteCommand(): Unmute the video.
- EnterFullscreenCommand(): Enter fullscreen mode.
- ExitFullscreenCommand(): Exit fullscreen mode.
- StartNextContentCommand(): Start the next content in the playlist.
- StartPreviousContentCommand(): Start the previous content in the playlist.
- SeekForwardCommand(time): Seek forward by the specified time (in seconds).
- SeekBackwardCommand(time): Seek backward by the specified time (in seconds).
- ShowUiCommand(): Show the player UI.
- HideUiCommand(): Hide the player UI.
- StartContentCommand(): Start the content.
Player Events #
The GreenVideoController emits the following events through the playerEvents stream:
- OnReadyEvent: Emitted when the player is ready to play content.
- OnPlayEvent: Emitted when the player starts playing.
- OnContentStartEvent: Emitted when the player starts the content.
- OnPauseEvent: Emitted when the player is paused.
- OnMuteEvent: Emitted when the player is muted.
- OnUnmuteEvent: Emitted when the player is unmuted.
- OnSeekEvent: Emitted when the player seeks to a new position.
- OnEnterFullscreenEvent: Emitted when the player enters fullscreen mode.
- OnExitFullscreenEvent: Emitted when the player exits fullscreen mode.
- OnShowUiEvent: Emitted when the player shows the UI.
- OnHideUiEvent: Emitted when the player hides the UI.
- OnEnterPipEvent: Emitted when the player enters picture-in-picture mode.
- OnExitPipEvent: Emitted when the player exits picture-in-picture mode.
- OnTimeUpdateEvent: Emitted when the player updates the current time.
- OnMilestoneReachedEvent: Emitted when the player reaches a milestone.
- OnPlayerInitEvent: Emitted when the player is initialized.
- OnErrorEvent: Emitted when the player encounters an error.
You can listen to these events using the playerEvents stream provided by the GreenVideoController.