refs #21: fix video aspect ratio

This commit is contained in:
Salvatore Giordano
2020-04-10 11:00:55 +02:00
parent e549ae89f7
commit 092fed6fdd
+17 -2
View File
@@ -39,6 +39,7 @@ class MessageWidget extends StatefulWidget {
this.isParent = false, this.isParent = false,
this.onMentionTap, this.onMentionTap,
this.showOtherMessageUsername = false, this.showOtherMessageUsername = false,
this.showVideoFullScreen = true,
}) : super(key: key); }) : super(key: key);
/// Function called on mention tap /// Function called on mention tap
@@ -65,6 +66,9 @@ class MessageWidget extends StatefulWidget {
/// True if this is the parent of the thread being showed /// True if this is the parent of the thread being showed
final bool isParent; final bool isParent;
/// True if the video player will allow fullscreen mode
final bool showVideoFullScreen;
@override @override
_MessageWidgetState createState() => _MessageWidgetState(); _MessageWidgetState createState() => _MessageWidgetState();
} }
@@ -944,13 +948,23 @@ class _MessageWidgetState extends State<MessageWidget>
_videoControllers[attachment.assetUrl] = videoController; _videoControllers[attachment.assetUrl] = videoController;
} }
return FutureBuilder<void>(
future: videoController.initialize(),
builder: (_, snapshot) {
if (snapshot.connectionState != ConnectionState.done) {
return Center(
child: CircularProgressIndicator(),
);
}
ChewieController chewieController; ChewieController chewieController;
if (_chuwieControllers.containsKey(attachment.assetUrl)) { if (_chuwieControllers.containsKey(attachment.assetUrl)) {
chewieController = _chuwieControllers[attachment.assetUrl]; chewieController = _chuwieControllers[attachment.assetUrl];
} else { } else {
chewieController = ChewieController( chewieController = ChewieController(
allowFullScreen: widget.showVideoFullScreen,
videoPlayerController: videoController, videoPlayerController: videoController,
autoInitialize: true, autoInitialize: false,
aspectRatio: videoController.value.aspectRatio,
errorBuilder: (_, e) { errorBuilder: (_, e) {
return Stack( return Stack(
children: <Widget>[ children: <Widget>[
@@ -975,12 +989,13 @@ class _MessageWidgetState extends State<MessageWidget>
}); });
_chuwieControllers[attachment.assetUrl] = chewieController; _chuwieControllers[attachment.assetUrl] = chewieController;
} }
return Chewie( return Chewie(
key: ValueKey<String>( key: ValueKey<String>(
'ATTACHMENT-${attachment.title}-${widget.message.id}'), 'ATTACHMENT-${attachment.title}-${widget.message.id}'),
controller: chewieController, controller: chewieController,
); );
},
);
} }
Future<void> _launchURL(String url) async { Future<void> _launchURL(String url) async {