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

Added seek forward and rewind buttons #717

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 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
84 changes: 65 additions & 19 deletions lib/src/cupertino/cupertino_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:chewie/src/helpers/utils.dart';
import 'package:chewie/src/models/option_item.dart';
import 'package:chewie/src/models/subtitle_model.dart';
import 'package:chewie/src/notifiers/index.dart';
import 'package:chewie/src/seek_rewind_button.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
Expand All @@ -22,12 +23,14 @@ class CupertinoControls extends StatefulWidget {
required this.backgroundColor,
required this.iconColor,
this.showPlayButton = true,
this.showSeekButton = true,
Key? key,
}) : super(key: key);

final Color backgroundColor;
final Color iconColor;
final bool showPlayButton;
final bool showSeekButton;

@override
State<StatefulWidget> createState() {
Expand Down Expand Up @@ -349,25 +352,48 @@ class _CupertinoControlsState extends State<CupertinoControls>
final bool isFinished = _latestValue.position >= _latestValue.duration;
final bool showPlayButton =
widget.showPlayButton && !_latestValue.isPlaying && !_dragging;

return GestureDetector(
onTap: _latestValue.isPlaying
? _cancelAndRestartTimer
: () {
_hideTimer?.cancel();

setState(() {
notifier.hideStuff = false;
});
},
child: CenterPlayButton(
backgroundColor: widget.backgroundColor,
iconColor: widget.iconColor,
isFinished: isFinished,
isPlaying: controller.value.isPlaying,
show: showPlayButton,
onPressed: _playPause,
),
Comment on lines -363 to -370
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cupertino controls already have the seek-forward and rewind buttons in the seek bar (i.e. the ones that rewind and fast-forward by 15 seconds).

As a result, this change should only apply to Material based widgets.

Do this for the other new widgets added in this PR, since they should only apply to Material.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello @diegotori

requested changes done please review

Thank you

final bool showSeekButton =
widget.showSeekButton && !_latestValue.isPlaying && !_dragging;

return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SeekRewindButton(
backgroundColor: Colors.black54,
iconColor: Colors.white,
show: showSeekButton,
onPressed: _seekRewind,
onDoublePressed: _seekRewind,
icon: Icons.fast_rewind,
),
maherjaafar marked this conversation as resolved.
Show resolved Hide resolved
GestureDetector(
onTap: _latestValue.isPlaying
? _cancelAndRestartTimer
: () {
_hideTimer?.cancel();

setState(() {
notifier.hideStuff = false;
});
},
child: CenterPlayButton(
backgroundColor: widget.backgroundColor,
iconColor: widget.iconColor,
isFinished: isFinished,
isPlaying: controller.value.isPlaying,
show: showSeekButton,
onPressed: _playPause,
),
),
SeekRewindButton(
backgroundColor: Colors.black54,
iconColor: Colors.white,
show: showPlayButton,
onPressed: _seekForward,
onDoublePressed: _seekForward,
icon: Icons.fast_forward,
),
],
);
}

Expand Down Expand Up @@ -806,6 +832,26 @@ class _CupertinoControlsState extends State<CupertinoControls>
_subtitlesPosition = controller.value.position;
});
}

void _seekForward() {
setState(() {
controller.seekTo(
Duration(
seconds: _latestValue.position.inSeconds + 10,
),
);
});
}

void _seekRewind() {
setState(() {
controller.seekTo(
Duration(
seconds: _latestValue.position.inSeconds - 10,
),
);
});
}
maherjaafar marked this conversation as resolved.
Show resolved Hide resolved
}

class _PlaybackSpeedDialog extends StatelessWidget {
Expand Down
100 changes: 73 additions & 27 deletions lib/src/material/material_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ import 'package:chewie/src/material/widgets/playback_speed_dialog.dart';
import 'package:chewie/src/models/option_item.dart';
import 'package:chewie/src/models/subtitle_model.dart';
import 'package:chewie/src/notifiers/index.dart';
import 'package:chewie/src/seek_rewind_button.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:video_player/video_player.dart';

class MaterialControls extends StatefulWidget {
const MaterialControls({
this.showPlayButton = true,
this.showSeekButton = true,
Key? key,
}) : super(key: key);

final bool showPlayButton;
final bool showSeekButton;

@override
State<StatefulWidget> createState() {
Expand Down Expand Up @@ -366,33 +369,56 @@ class _MaterialControlsState extends State<MaterialControls>
final bool isFinished = _latestValue.position >= _latestValue.duration;
final bool showPlayButton =
widget.showPlayButton && !_dragging && !notifier.hideStuff;

return GestureDetector(
onTap: () {
if (_latestValue.isPlaying) {
if (_displayTapped) {
setState(() {
notifier.hideStuff = true;
});
} else {
_cancelAndRestartTimer();
}
} else {
_playPause();

setState(() {
notifier.hideStuff = true;
});
}
},
child: CenterPlayButton(
backgroundColor: Colors.black54,
iconColor: Colors.white,
isFinished: isFinished,
isPlaying: controller.value.isPlaying,
show: showPlayButton,
onPressed: _playPause,
),
final bool showSeekButton =
widget.showSeekButton && !_dragging && !notifier.hideStuff;

return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SeekRewindButton(
backgroundColor: Colors.black54,
iconColor: Colors.white,
show: showSeekButton,
onPressed: _seekRewind,
onDoublePressed: _seekRewind,
icon: Icons.fast_rewind,
),
GestureDetector(
onTap: () {
if (_latestValue.isPlaying) {
if (_displayTapped) {
setState(() {
notifier.hideStuff = true;
});
} else {
_cancelAndRestartTimer();
}
} else {
_playPause();

setState(() {
notifier.hideStuff = true;
});
}
},
child: CenterPlayButton(
backgroundColor: Colors.black54,
iconColor: Colors.white,
isFinished: isFinished,
isPlaying: controller.value.isPlaying,
show: showPlayButton,
onPressed: _playPause,
),
),
SeekRewindButton(
backgroundColor: Colors.black54,
iconColor: Colors.white,
show: showSeekButton,
onPressed: _seekForward,
onDoublePressed: _seekForward,
icon: Icons.fast_forward,
),
],
maherjaafar marked this conversation as resolved.
Show resolved Hide resolved
);
}

Expand Down Expand Up @@ -542,6 +568,26 @@ class _MaterialControlsState extends State<MaterialControls>
});
}

void _seekForward() {
setState(() {
controller.seekTo(
Duration(
seconds: _latestValue.position.inSeconds + 10,
),
);
});
}

void _seekRewind() {
setState(() {
controller.seekTo(
Duration(
seconds: _latestValue.position.inSeconds - 10,
),
);
});
}

void _startHideTimer() {
final hideControlsTimer = chewieController.hideControlsTimer.isNegative
? ChewieController.defaultHideControlsTimer
Expand Down
100 changes: 73 additions & 27 deletions lib/src/material/material_desktop_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ import 'package:chewie/src/material/widgets/playback_speed_dialog.dart';
import 'package:chewie/src/models/option_item.dart';
import 'package:chewie/src/models/subtitle_model.dart';
import 'package:chewie/src/notifiers/index.dart';
import 'package:chewie/src/seek_rewind_button.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:video_player/video_player.dart';

class MaterialDesktopControls extends StatefulWidget {
const MaterialDesktopControls({
this.showPlayButton = true,
this.showSeekButton = true,
Key? key,
}) : super(key: key);

final bool showPlayButton;
final bool showSeekButton;

@override
State<StatefulWidget> createState() {
Expand Down Expand Up @@ -330,33 +333,56 @@ class _MaterialDesktopControlsState extends State<MaterialDesktopControls>
final bool isFinished = _latestValue.position >= _latestValue.duration;
final bool showPlayButton =
widget.showPlayButton && !_dragging && !notifier.hideStuff;

return GestureDetector(
onTap: () {
if (_latestValue.isPlaying) {
if (_displayTapped) {
setState(() {
notifier.hideStuff = true;
});
} else {
_cancelAndRestartTimer();
}
} else {
_playPause();

setState(() {
notifier.hideStuff = true;
});
}
},
child: CenterPlayButton(
backgroundColor: Colors.black54,
iconColor: Colors.white,
isFinished: isFinished,
isPlaying: controller.value.isPlaying,
show: showPlayButton,
onPressed: _playPause,
),
final bool showSeekButton =
widget.showSeekButton && !_dragging && !notifier.hideStuff;

return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
SeekRewindButton(
backgroundColor: Colors.black54,
iconColor: Colors.white,
show: showSeekButton,
onPressed: _seekRewind,
onDoublePressed: _seekRewind,
icon: Icons.fast_rewind,
),
GestureDetector(
onTap: () {
if (_latestValue.isPlaying) {
if (_displayTapped) {
setState(() {
notifier.hideStuff = true;
});
} else {
_cancelAndRestartTimer();
}
} else {
_playPause();

setState(() {
notifier.hideStuff = true;
});
}
},
child: CenterPlayButton(
backgroundColor: Colors.black54,
iconColor: Colors.white,
isFinished: isFinished,
isPlaying: controller.value.isPlaying,
show: showPlayButton,
onPressed: _playPause,
),
),
SeekRewindButton(
backgroundColor: Colors.black54,
iconColor: Colors.white,
show: showSeekButton,
onPressed: _seekForward,
onDoublePressed: _seekForward,
icon: Icons.fast_forward,
),
],
);
}

Expand Down Expand Up @@ -596,4 +622,24 @@ class _MaterialDesktopControlsState extends State<MaterialDesktopControls>
),
);
}

void _seekForward() {
setState(() {
controller.seekTo(
Duration(
seconds: _latestValue.position.inSeconds + 10,
),
);
});
}

void _seekRewind() {
setState(() {
controller.seekTo(
Duration(
seconds: _latestValue.position.inSeconds - 10,
),
);
});
}
}
Loading