As the title says, is it possible to have a video fill the screen without visible stretching? If so, how would I do this with chewie?
Link to chewie: https://pub.dev/packages/chewie
The player fills the screen but the video is stretched because I've used MediaQuerys, but I don't know any other way to change the size of the player other than provide an aspectratio. I need to preserve the video's aspectratio but also have the video fit the screen.
My current code:
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:chewie/chewie.dart';
import 'package:video_player/video_player.dart';
class MyVideoPlayer extends StatefulWidget {
final String path;
MyVideoPlayer({Key key, @required this.path}) : super(key: key);
@override
_MyVideoPlayerState createState() => new _MyVideoPlayerState();
}
class _MyVideoPlayerState extends State<MyVideoPlayer> {
VideoPlayerController _videoPlayerController;
ChewieController _chewieController;
Future<void> _future;
TargetPlatform _platform;
Future<void> initVideoPlayer() async {
await _videoPlayerController.initialize();
setState(() {
print(_videoPlayerController.value.aspectRatio);
_chewieController = ChewieController(
aspectRatio: MediaQuery.of(context).size.width/ MediaQuery.of(context).size.height,
videoPlayerController: _videoPlayerController,
autoPlay: false,
looping: false,
// showControls: false,
materialProgressColors: ChewieProgressColors(
playedColor: Colors.red,
handleColor: Colors.blue,
backgroundColor: Colors.grey,
bufferedColor: Colors.lightGreen,
),
// placeholder: Container(
// color: Colors.grey,
// ),
);
});
}
@override
void initState() {
super.initState();
// _controller = VideoPlayerController.network('https://www.sample-videos.com/video123/mp4/720/big_buck_bunny_720p_20mb.mp4');
_videoPlayerController = VideoPlayerController.file(File(widget.path));
_future = initVideoPlayer();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.light().copyWith(
platform: _platform ?? Theme.of(context).platform,
),
home: Scaffold(
body: FutureBuilder(
future: _future,
builder: (context, snapshot) {
return _videoPlayerController.value.initialized
? Chewie(
controller: _chewieController,
)
: Center(child: CircularProgressIndicator());
}),
),
);
}
@override
void dispose() {
_videoPlayerController.dispose();
_chewieController.dispose();
super.dispose();
}
}