Credit to https://github.com/brianegan/chewie for creating Chewie, and to https://github.com/kirill09/chewie for adding subtitle support.
I've made a few tweaks and added usage instructions below.
Please visit https://pub.dev/packages/chewie for Chewie installation instructions and support.
In your pubspec.yaml
file within your Flutter Project:
dependencies:
chewie:
git:
url: https://github.com/LampeMW/chewie
ref: subtitles
You can use either local SRT files or pull SRT files from a URL
Assets:
String subtitles = await DefaultAssetBundle.of(context).loadString('assets/SrtFile.srt');
URL:
String subtitles = await NetworkAssetBundle(Uri.parse(<srtUrl>)).loadString(<srtUrl>);
Create VideoPlayerController with either a url or local video file
import 'package:chewie/chewie.dart';
final videoPlayerController = VideoPlayerController.network(
'https://flutter.github.io/assets-for-api-docs/videos/butterfly.mp4');
Create your Chewie Controller:
final chewieController = ChewieController(
videoPlayerController: videoPlayerController,
aspectRatio: 3 / 2,
autoPlay: true,
looping: true,
);
And set the subtitles:
chewieController.setSubtitle(subtitles);
And finally, create your Chewie widget:
final playerWidget = Chewie(
controller: chewieController,
);
Please make sure to dispose both controller widgets after use. For example by overriding the dispose method of the a StatefulWidget
:
@override
void dispose() {
videoPlayerController.dispose();
chewieController.dispose();
super.dispose();
}
The video player plugin used by chewie is not functional on iOS simulators. An iOS device must be used during development/testing. Please refer to this issue.