Skip to content
Open
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
9 changes: 9 additions & 0 deletions lib/src/chewie_player.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'dart:async';

import 'package:chewie/src/chewie_progress_colors.dart';
import 'package:chewie/src/models/chewie_chapter.dart';
import 'package:chewie/src/models/option_item.dart';
import 'package:chewie/src/models/options_translation.dart';
import 'package:chewie/src/models/subtitle_model.dart';
Expand Down Expand Up @@ -335,6 +336,7 @@ class ChewieController extends ChangeNotifier {
this.hideControlsTimer = defaultHideControlsTimer,
this.controlsSafeAreaMinimum = EdgeInsets.zero,
this.pauseOnBackgroundTap = false,
this.chapters = const [],
}) : assert(
playbackSpeeds.every((speed) => speed > 0),
'The playbackSpeeds values must all be greater than 0',
Expand Down Expand Up @@ -394,6 +396,7 @@ class ChewieController extends ChangeNotifier {
)?
routePageBuilder,
bool? pauseOnBackgroundTap,
List<ChewieChapter>? chapters,
}) {
return ChewieController(
draggableProgressBar: draggableProgressBar ?? this.draggableProgressBar,
Expand Down Expand Up @@ -458,6 +461,7 @@ class ChewieController extends ChangeNotifier {
progressIndicatorDelay:
progressIndicatorDelay ?? this.progressIndicatorDelay,
pauseOnBackgroundTap: pauseOnBackgroundTap ?? this.pauseOnBackgroundTap,
chapters: chapters ?? this.chapters,
);
}

Expand Down Expand Up @@ -630,6 +634,11 @@ class ChewieController extends ChangeNotifier {
/// Defines if the player should pause when the background is tapped
final bool pauseOnBackgroundTap;

/// Chapters of the video, sorted by ascending start time.
/// When non-empty, the progress bar is split into chapter segments and the
/// hovered/scrubbed chapter title is displayed above the bar.
final List<ChewieChapter> chapters;

static ChewieController of(BuildContext context) {
final chewieControllerProvider = context
.dependOnInheritedWidgetOfExactType<ChewieControllerProvider>()!;
Expand Down
1 change: 1 addition & 0 deletions lib/src/cupertino/cupertino_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ class _CupertinoControlsState extends State<CupertinoControls>
padding: const EdgeInsets.only(right: 12.0),
child: CupertinoVideoProgressBar(
controller,
chapters: chewieController.chapters,
onDragStart: () {
setState(() {
_dragging = true;
Expand Down
4 changes: 4 additions & 0 deletions lib/src/cupertino/cupertino_progress_bar.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:chewie/src/chewie_progress_colors.dart';
import 'package:chewie/src/models/chewie_chapter.dart';
import 'package:chewie/src/progress_bar.dart';
import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart';
Expand All @@ -13,8 +14,10 @@ class CupertinoVideoProgressBar extends StatelessWidget {
this.onDragUpdate,
super.key,
this.draggableProgressBar = true,
this.chapters = const [],
}) : colors = colors ?? ChewieProgressColors();

final List<ChewieChapter> chapters;
final VideoPlayerController controller;
final ChewieProgressColors colors;
final Function()? onDragStart;
Expand All @@ -34,6 +37,7 @@ class CupertinoVideoProgressBar extends StatelessWidget {
onDragStart: onDragStart,
onDragUpdate: onDragUpdate,
draggableProgressBar: draggableProgressBar,
chapters: chapters,
);
}
}
1 change: 1 addition & 0 deletions lib/src/material/material_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -639,6 +639,7 @@ class _MaterialControlsState extends State<MaterialControls>
return Expanded(
child: MaterialVideoProgressBar(
controller,
chapters: chewieController.chapters,
onDragStart: () {
setState(() {
_dragging = true;
Expand Down
1 change: 1 addition & 0 deletions lib/src/material/material_desktop_controls.dart
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ class _MaterialDesktopControlsState extends State<MaterialDesktopControls>
return Expanded(
child: MaterialVideoProgressBar(
controller,
chapters: chewieController.chapters,
onDragStart: () {
setState(() {
_dragging = true;
Expand Down
4 changes: 4 additions & 0 deletions lib/src/material/material_progress_bar.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:chewie/src/chewie_progress_colors.dart';
import 'package:chewie/src/models/chewie_chapter.dart';
import 'package:chewie/src/progress_bar.dart';
import 'package:flutter/material.dart';
import 'package:video_player/video_player.dart';
Expand All @@ -15,8 +16,10 @@ class MaterialVideoProgressBar extends StatelessWidget {
this.onDragUpdate,
super.key,
this.draggableProgressBar = true,
this.chapters = const [],
}) : colors = colors ?? ChewieProgressColors();

final List<ChewieChapter> chapters;
final double height;
final double barHeight;
final double handleHeight;
Expand All @@ -39,6 +42,7 @@ class MaterialVideoProgressBar extends StatelessWidget {
onDragStart: onDragStart,
onDragUpdate: onDragUpdate,
draggableProgressBar: draggableProgressBar,
chapters: chapters,
);
}
}
6 changes: 6 additions & 0 deletions lib/src/models/chewie_chapter.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class ChewieChapter {
const ChewieChapter({required this.title, required this.start});

final String title;
final Duration start;
}
1 change: 1 addition & 0 deletions lib/src/models/index.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export 'chewie_chapter.dart';
export 'option_item.dart';
export 'options_translation.dart';
export 'subtitle_model.dart';
Loading