green_video 2.0.46 copy "green_video: ^2.0.46" to clipboard
green_video: ^2.0.46 copied to clipboard

Green Video Player Flutter plugin.

green_video #

Green Video Player for Flutter

Getting Started #

  1. Import the green_video dependency in your pubspec.yaml
dependencies: 
  green_video: <version>
  1. import the player widget
import 'package:green_video/widgets/green_video.dart';
  1. 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",
            mixId: "MIX_ID",
            contentId: "CONTENT_ID",
            controller: /* a green video controller instance */,
          ),
        ],
      ),
    ),
  );
}
  1. GreenVideo parameters

mandatory fields #

  • licenseKey: License key
  • embedId: Id of the configuration

optional fields #

  • mixId: Id of the mix. The value would override default mixId from the embedded configuration
  • contentId: Id of the first content from the mix. It would be moved to the first position
  • adTagUrl: tag url for advertisement
  • consentString: Consent string
  • adsDisallowed: The flag to disable advertisement
  • environment: 'prod' or 'stage' environment
  • debug: Enables detailed loging in the SDK
  • controller: connects a controller to the player
  1. 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}");
  }
});
  1. 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

Player Commands #

The GreenVideoController provides the following commands to control the player:

  • StartContentCommand(): Start the content.
  • 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.

Player Events #

The GreenVideoController emits the following events through the playerEvents stream:

  • OnPlayerInitEvent: Emitted when the player is initialized.
  • 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.
  • OnErrorEvent: Emitted when the player encounters an error.

You can listen to these events using the playerEvents stream provided by the GreenVideoController.