Skip to content

Subtitles are off by default and option to disable fully #865

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions example/lib/app/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class _ChewieDemoState extends State<ChewieDemo> {
late VideoPlayerController _videoPlayerController2;
ChewieController? _chewieController;
int? bufferDelay;
bool _showSubtitles = false;

@override
void initState() {
Expand Down Expand Up @@ -113,6 +114,7 @@ class _ChewieDemoState extends State<ChewieDemo> {
videoPlayerController: _videoPlayerController1,
autoPlay: true,
looping: true,
showSubtitle: _showSubtitles,
progressIndicatorDelay:
bufferDelay != null ? Duration(milliseconds: bufferDelay!) : null,

Expand Down Expand Up @@ -198,11 +200,27 @@ class _ChewieDemoState extends State<ChewieDemo> {
),
),
),
TextButton(
onPressed: () {
_chewieController?.enterFullScreen();
},
child: const Text('Fullscreen'),
Row(
children: <Widget>[
Expanded(
child: TextButton(
onPressed: () {
_chewieController?.enterFullScreen();
},
child: const Text('Fullscreen'),
),
),
Expanded(
child: TextButton(
onPressed: () {
setState(() {
_showSubtitles = !_showSubtitles;
});
},
child: const Text('Toggle Subtitles'),
),
),
],
),
Row(
children: <Widget>[
Expand Down
10 changes: 10 additions & 0 deletions lib/src/chewie_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ class ChewieController extends ChangeNotifier {
this.zoomAndPan = false,
this.maxScale = 2.5,
this.subtitle,
this.showSubtitle = false,
this.subtitleBuilder,
this.customControls,
this.errorBuilder,
Expand Down Expand Up @@ -339,6 +340,7 @@ class ChewieController extends ChangeNotifier {
bool? zoomAndPan,
double? maxScale,
Subtitles? subtitle,
bool? showSubtitle,
Widget Function(BuildContext, dynamic)? subtitleBuilder,
Widget? customControls,
WidgetBuilder? bufferingBuilder,
Expand Down Expand Up @@ -392,6 +394,7 @@ class ChewieController extends ChangeNotifier {
additionalOptions: additionalOptions ?? this.additionalOptions,
showControls: showControls ?? this.showControls,
subtitle: subtitle ?? this.subtitle,
showSubtitle: showSubtitle ?? this.showSubtitle,
subtitleBuilder: subtitleBuilder ?? this.subtitleBuilder,
customControls: customControls ?? this.customControls,
errorBuilder: errorBuilder ?? this.errorBuilder,
Expand Down Expand Up @@ -454,6 +457,13 @@ class ChewieController extends ChangeNotifier {
/// Add a List of Subtitles here in `Subtitles.subtitle`
Subtitles? subtitle;

///
/// Whether to display subtitles.
///
/// By default, this is set to `false`, which hides them.
///
final bool showSubtitle;

/// The controller for the video you want to play
final VideoPlayerController videoPlayerController;

Expand Down
1 change: 0 additions & 1 deletion lib/src/cupertino/cupertino_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,6 @@ class _CupertinoControlsState extends State<CupertinoControls>
}

Future<void> _initialize() async {
_subtitleOn = chewieController.subtitle?.isNotEmpty ?? false;
controller.addListener(_updateState);

_updateState();
Expand Down
5 changes: 4 additions & 1 deletion lib/src/helpers/adaptive_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ class AdaptiveControls extends StatelessWidget {
super.key,
});


@override
Widget build(BuildContext context) {
Widget build(
BuildContext context,
) {
switch (Theme.of(context).platform) {
case TargetPlatform.android:
case TargetPlatform.fuchsia:
Expand Down
6 changes: 3 additions & 3 deletions lib/src/material/material_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ class _MaterialControlsState extends State<MaterialControls>
0.0,
notifier.hideStuff ? barHeight * 0.8 : 0.0,
),
child:
_buildSubtitles(context, chewieController.subtitle!),
child: chewieController.showSubtitle
? _buildSubtitles(context, chewieController.subtitle!)
: const SizedBox(),
),
_buildBottomBar(context),
],
Expand Down Expand Up @@ -524,7 +525,6 @@ class _MaterialControlsState extends State<MaterialControls>
}

Future<void> _initialize() async {
_subtitleOn = chewieController.subtitle?.isNotEmpty ?? false;
controller.addListener(_updateState);

_updateState();
Expand Down
6 changes: 3 additions & 3 deletions lib/src/material/material_desktop_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,9 @@ class _MaterialDesktopControlsState extends State<MaterialDesktopControls>
0.0,
notifier.hideStuff ? barHeight * 0.8 : 0.0,
),
child:
_buildSubtitles(context, chewieController.subtitle!),
child: chewieController.showSubtitle
? _buildSubtitles(context, chewieController.subtitle!)
: Container(),
),
_buildBottomBar(context),
],
Expand Down Expand Up @@ -466,7 +467,6 @@ class _MaterialDesktopControlsState extends State<MaterialDesktopControls>
}

Future<void> _initialize() async {
_subtitleOn = chewieController.subtitle?.isNotEmpty ?? false;
controller.addListener(_updateState);

_updateState();
Expand Down
9 changes: 3 additions & 6 deletions lib/src/player_with_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,15 @@ class PlayerWithControls extends StatelessWidget {
) {
return Stack(
children: <Widget>[
if (chewieController.placeholder != null)
chewieController.placeholder!,
if (chewieController.placeholder != null) chewieController.placeholder!,
InteractiveViewer(
transformationController: chewieController.transformationController,
maxScale: chewieController.maxScale,
panEnabled: chewieController.zoomAndPan,
scaleEnabled: chewieController.zoomAndPan,
child: Center(
child: AspectRatio(
aspectRatio: chewieController.aspectRatio ??
chewieController.videoPlayerController.value.aspectRatio,
aspectRatio: chewieController.aspectRatio ?? chewieController.videoPlayerController.value.aspectRatio,
child: VideoPlayer(chewieController.videoPlayerController),
),
),
Expand Down Expand Up @@ -83,8 +81,7 @@ class PlayerWithControls extends StatelessWidget {
);
}

return LayoutBuilder(
builder: (BuildContext context, BoxConstraints constraints) {
return LayoutBuilder(builder: (BuildContext context, BoxConstraints constraints) {
return Center(
child: SizedBox(
height: constraints.maxHeight,
Expand Down