Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add ability to add watermark (e.g. username, logo...) above the video. #293

Open
wants to merge 9 commits into
base: development
Choose a base branch
from
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,7 @@ Updated wakelock to wakelock_plus: ^1.1.4
Updated video_player to latest version video_player: ^2.8.6

Fix - Formatting

## 0.9.0

Fix - Registering the context and initializes the FlickManager after the widget is built to ensure the context is available.
1 change: 1 addition & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencies:
flick_video_player:
path: "../"
video_player: ^2.8.6
wakelock_web: ^0.4.0
provider: ^6.0.1

# The following adds the Cupertino Icons font to your application.
Expand Down
27 changes: 19 additions & 8 deletions lib/src/controls/flick_video_with_controls.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter/material.dart';
import 'package:flick_video_player/flick_video_player.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:video_player/video_player.dart';

Expand Down Expand Up @@ -40,6 +40,7 @@ class FlickVideoWithControls extends StatefulWidget {
color: Colors.white,
fontSize: 12,
),
this.watermark,
}) : super(key: key);

/// Create custom controls or use any of these [FlickPortraitControls], [FlickLandscapeControls]
Expand Down Expand Up @@ -84,6 +85,11 @@ class FlickVideoWithControls extends StatefulWidget {
/// If false videoPlayerController will not be updated.
final bool willVideoPlayerControllerChange;

/// A widget to always display over the video.
///
/// Use [Positioned], [Align] or [Center] to position the watermark.
final Widget? watermark;

get videoPlayerController => null;

@override
Expand Down Expand Up @@ -120,17 +126,20 @@ class _FlickVideoWithControlsState extends State<FlickVideoWithControls> {
child: Stack(
children: <Widget>[
Center(
child: FlickNativeVideoPlayer(
videoPlayerController: _videoPlayerController,
fit: widget.videoFit,
aspectRatioWhenLoading: widget.aspectRatioWhenLoading,
),
child: _videoPlayerController != null
? FlickNativeVideoPlayer(
videoPlayerController: _videoPlayerController!,
fit: widget.videoFit,
aspectRatioWhenLoading: widget.aspectRatioWhenLoading,
)
: widget.playerLoadingFallback,
),
if (widget.watermark != null) widget.watermark!,
Positioned.fill(
child: Stack(
alignment: Alignment.bottomCenter,
children: <Widget>[
_videoPlayerController!.closedCaptionFile != null &&
_videoPlayerController?.closedCaptionFile != null &&
_showVideoCaption
? Positioned(
bottom: 5,
Expand All @@ -148,7 +157,9 @@ class _FlickVideoWithControlsState extends State<FlickVideoWithControls> {
widget.playerLoadingFallback,
if (_videoPlayerController?.value.hasError == true)
widget.playerErrorFallback,
widget.controls ?? Container(),
if (_videoPlayerController != null &&
_videoPlayerController!.value.isInitialized)
widget.controls ?? Container(),
],
),
),
Expand Down
14 changes: 11 additions & 3 deletions lib/src/flick_video_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,19 @@ class _FlickVideoPlayerState extends State<FlickVideoPlayer>

@override
void initState() {
super.initState();

WidgetsBinding.instance.addObserver(this);
flickManager = widget.flickManager;
flickManager.registerContext(context);

// Register context and perform initialization in post-frame callback
WidgetsBinding.instance.addPostFrameCallback((_) {
flickManager.registerContext(context);
_initializeFlickManager();
});
}

void _initializeFlickManager() {
flickManager.flickControlManager!.addListener(listener);
_setSystemUIOverlays();
_setPreferredOrientation();
Expand All @@ -94,8 +104,6 @@ class _FlickVideoPlayerState extends State<FlickVideoPlayer>
.listen(_webFullscreenListener);
document.documentElement?.onKeyDown.listen(_webKeyListener);
}

super.initState();
}

@override
Expand Down
4 changes: 3 additions & 1 deletion lib/src/manager/video_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ class FlickVideoManager extends ChangeNotifier {
.seekTo(Duration(hours: 0, minutes: 0, seconds: 0, milliseconds: 0));
}

if (autoPlay && ModalRoute.of(_flickManager._context!)!.isCurrent) {
if (autoPlay &&
_flickManager._context != null &&
ModalRoute.of(_flickManager._context!)?.isCurrent == true) {
//Chrome's autoplay policies are simple:
//Muted autoplay is always allowed.
if (kIsWeb) _flickManager.flickControlManager!.mute();
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: Flick Video Player is a video player for flutter. The video_player
repository: https://github.com/GeekyAnts/flick-video-player
homepage: https://github.com/GeekyAnts/flick-video-player

version: 0.8.0
version: 0.9.0

environment:
sdk: ">=3.2.3 <4.0.0"
Expand Down