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

Video Tweets with initial volume #33

Closed
ivanjpg opened this issue Apr 28, 2020 · 3 comments
Closed

Video Tweets with initial volume #33

ivanjpg opened this issue Apr 28, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@ivanjpg
Copy link
Contributor

ivanjpg commented Apr 28, 2020

The tweets with video embedded are hardcoded to start with a 0.0 volume, I found in this file:

lib/src/tweet_video.dart

Is there a possibility to add an option to set a default initial volume?

I think it would be possible by adding to TweetView class a new double property, then passing it to MediaContainer and finally to TweetVideo. At least it looks so much straight forward than add a way to access the Chewie controller.

Thank you so much! (again)

I think this could be done in this dirty way:

diff --git a/lib/src/media_container.dart b/lib/src/media_container.dart
index f4876d5..fc17564 100644
--- a/lib/src/media_container.dart
+++ b/lib/src/media_container.dart
@@ -19,12 +19,14 @@ class MediaContainer extends StatefulWidget {
     this.viewMode, {
     Key key,
     this.useVideoPlayer = true,
+    this.videoPlayerInitialVolume = 0.0,
     this.onTapImage,
   }) : super(key: key);

   final TweetVM tweetVM;
   final ViewMode viewMode;
   final bool useVideoPlayer;
+  final double videoPlayerInitialVolume;

   @override
   _MediaContainerState createState() => _MediaContainerState();
@@ -47,7 +49,10 @@ class _MediaContainerState extends State<MediaContainer>
     Widget child;
     if (widget.tweetVM.getDisplayTweet().hasSupportedVideo) {
       if (widget.useVideoPlayer) {
-        child = TweetVideo(widget.tweetVM.getDisplayTweet());
+        child = TweetVideo(
+          widget.tweetVM.getDisplayTweet(),
+          initialVolume: widget.videoPlayerInitialVolume
+        );
       } else {
         child = Stack(
           children: <Widget>[
diff --git a/lib/src/tweet_video.dart b/lib/src/tweet_video.dart
index b7ace27..a85ae36 100644
--- a/lib/src/tweet_video.dart
+++ b/lib/src/tweet_video.dart
@@ -9,9 +9,11 @@ class TweetVideo extends StatefulWidget {
   TweetVideo(
     this.tweetVM, {
     Key key,
+    this.initialVolume = 0.0
   }) : super(key: key);

   final TweetVM tweetVM;
+  final double initialVolume;

   @override
   _TweetVideoState createState() => _TweetVideoState();
@@ -27,7 +29,7 @@ class _TweetVideoState extends State<TweetVideo>
     super.initState();
     _controller = VideoPlayerController.network(
         widget.tweetVM.getDisplayTweet().videoUrl);
-    _controller.setVolume(0.0);
+    _controller.setVolume(widget.initialVolume);

     _chewieController = ChewieController(
       videoPlayerController: _controller,
diff --git a/lib/tweet_view.dart b/lib/tweet_view.dart
index 660b3bc..4b32fa3 100644
--- a/lib/tweet_view.dart
+++ b/lib/tweet_view.dart
@@ -58,6 +58,9 @@ class TweetView extends StatelessWidget {
   /// If set to false a image placeholder will he shown and a video will be played in a new page.
   final bool useVideoPlayer;

+  /// If the Tweet contains a video then an initial volume can be specified with a value between 0.0 and 1.0.
+  final double videoPlayerInitialVolume;
+
   /// Function used when you want a custom image tapped callback
   final OnTapImage onTapImage;

@@ -79,6 +82,7 @@ class TweetView extends StatelessWidget {
     this.quoteBackgroundColor,
     this.backgroundColor,
     this.useVideoPlayer,
+    this.videoPlayerInitialVolume,
     this.onTapImage,
     this.createdDateDisplayFormat,
   }); //  TweetView(this.tweetVM);
@@ -97,6 +101,7 @@ class TweetView extends StatelessWidget {
       this.quoteBackgroundColor = Colors.white,
       this.backgroundColor = Colors.white,
       this.useVideoPlayer = true,
+      this.videoPlayerInitialVolume = 0.0,
       this.onTapImage,
       this.createdDateDisplayFormat})
       : _tweetVM = TweetVM.fromApiModel(tweet, createdDateDisplayFormat);
@@ -111,6 +116,7 @@ class TweetView extends StatelessWidget {
             _tweetVM,
             ViewMode.standard,
             useVideoPlayer: useVideoPlayer,
+            videoPlayerInitialVolume: videoPlayerInitialVolume,
             onTapImage: onTapImage,
           ),
           GestureDetector(
@ivanjpg ivanjpg added the enhancement New feature or request label Apr 28, 2020
@kawa89
Copy link
Collaborator

kawa89 commented Apr 28, 2020

Sure. I have a bug to fix on my next "window" for this library ;)
Maybe you want to make a Pull Request with those changes? ;)

@ivanjpg
Copy link
Contributor Author

ivanjpg commented Apr 28, 2020

Done, a Pull Request has been made: #34

@kawa89
Copy link
Collaborator

kawa89 commented May 8, 2020

Released with version 2.2.0

@kawa89 kawa89 closed this as completed May 8, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants