Skip to content

Commit

Permalink
Add callback for thumbnail loading complete
Browse files Browse the repository at this point in the history
  • Loading branch information
sbis04 committed Oct 29, 2022
1 parent 2e42a55 commit a08b933
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/src/trim_viewer/fixed_viewer/fixed_thumbnail_viewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class FixedThumbnailViewer extends StatelessWidget {
final double thumbnailHeight;
final BoxFit fit;
final int numberOfThumbnails;
final VoidCallback onThumbnailLoadingComplete;
final int quality;

/// For showing the thumbnails generated from the video,
Expand All @@ -22,6 +23,7 @@ class FixedThumbnailViewer extends StatelessWidget {
required this.thumbnailHeight,
required this.numberOfThumbnails,
required this.fit,
required this.onThumbnailLoadingComplete,
this.quality = 75,
}) : super(key: key);

Expand Down Expand Up @@ -50,6 +52,9 @@ class FixedThumbnailViewer extends StatelessWidget {
bytes = lastBytes;
}
byteList.add(bytes);
if (byteList.length == numberOfThumbnails) {
onThumbnailLoadingComplete();
}
yield byteList;
}
}
Expand Down
4 changes: 4 additions & 0 deletions lib/src/trim_viewer/fixed_viewer/fixed_trim_viewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ class FixedTrimViewer extends StatefulWidget {
/// Properties for customizing the fixed trim area.
final FixedTrimAreaProperties areaProperties;

final VoidCallback onThumbnailLoadingComplete;

/// Widget for displaying the video trimmer.
///
/// This has frame wise preview of the video with a
Expand Down Expand Up @@ -107,6 +109,7 @@ class FixedTrimViewer extends StatefulWidget {
const FixedTrimViewer({
super.key,
required this.trimmer,
required this.onThumbnailLoadingComplete,
this.viewerWidth = 50.0 * 8,
this.viewerHeight = 50,
this.maxVideoLength = const Duration(milliseconds: 0),
Expand Down Expand Up @@ -201,6 +204,7 @@ class _FixedTrimViewerState extends State<FixedTrimViewer>
thumbnailHeight: _thumbnailViewerH,
numberOfThumbnails: _numberOfThumbnails,
quality: widget.areaProperties.thumbnailQuality,
onThumbnailLoadingComplete: widget.onThumbnailLoadingComplete,
);
this.thumbnailWidget = thumbnailWidget;
Duration totalDuration = videoPlayerController.value.duration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class ScrollableThumbnailViewer extends StatelessWidget {
final int numberOfThumbnails;
final int quality;
final ScrollController scrollController;
final VoidCallback onThumbnailLoadingComplete;

/// For showing the thumbnails generated from the video,
/// like a frame by frame preview
Expand All @@ -24,6 +25,7 @@ class ScrollableThumbnailViewer extends StatelessWidget {
required this.numberOfThumbnails,
required this.fit,
required this.scrollController,
required this.onThumbnailLoadingComplete,
this.quality = 75,
}) : super(key: key);

Expand Down Expand Up @@ -52,6 +54,9 @@ class ScrollableThumbnailViewer extends StatelessWidget {
bytes = lastBytes;
}
byteList.add(bytes);
if (byteList.length == numberOfThumbnails) {
onThumbnailLoadingComplete();
}
yield byteList;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class ScrollableTrimViewer extends StatefulWidget {
/// Properties for customizing the trim area.
final TrimAreaProperties areaProperties;

final VoidCallback onThumbnailLoadingComplete;

/// Widget for displaying the video trimmer.
///
/// This has frame wise preview of the video with a
Expand Down Expand Up @@ -114,6 +116,7 @@ class ScrollableTrimViewer extends StatefulWidget {
super.key,
required this.trimmer,
required this.maxVideoLength,
required this.onThumbnailLoadingComplete,
this.viewerWidth = 50 * 8,
this.viewerHeight = 50,
this.showDuration = true,
Expand Down Expand Up @@ -331,6 +334,7 @@ class _ScrollableTrimViewerState extends State<ScrollableTrimViewer>
thumbnailHeight: _thumbnailViewerH,
numberOfThumbnails: _numberOfThumbnails,
quality: widget.areaProperties.thumbnailQuality,
onThumbnailLoadingComplete: widget.onThumbnailLoadingComplete,
);
this.thumbnailWidget = thumbnailWidget;
log('=========================');
Expand Down
19 changes: 19 additions & 0 deletions lib/src/trim_viewer/trim_viewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ class TrimViewer extends StatefulWidget {
/// Properties for customizing the trim area.
final TrimAreaProperties areaProperties;

/// Callback for thumbnail loader to know when all the
/// thumbnails are loaded.
final VoidCallback? onThumbnailLoadingComplete;

/// Widget for displaying the video trimmer.
///
/// This has frame wise preview of the video with a
Expand Down Expand Up @@ -154,6 +158,10 @@ class TrimViewer extends StatefulWidget {
///
/// * [areaProperties] defines properties for customizing the trim area.
///
///
/// * [onThumbnailLoadingComplete] is a callback for thumbnail loader to
/// know when all the thumbnails are loaded.
///
const TrimViewer({
Key? key,
required this.trimmer,
Expand All @@ -169,6 +177,7 @@ class TrimViewer extends StatefulWidget {
this.paddingFraction = 0.2,
this.editorProperties = const TrimEditorProperties(),
this.areaProperties = const TrimAreaProperties(),
this.onThumbnailLoadingComplete,
}) : super(key: key);

@override
Expand Down Expand Up @@ -218,6 +227,11 @@ class _TrimViewerState extends State<TrimViewer> with TickerProviderStateMixin {
paddingFraction: widget.paddingFraction,
editorProperties: widget.editorProperties,
areaProperties: widget.areaProperties,
onThumbnailLoadingComplete: () {
if (widget.onThumbnailLoadingComplete != null) {
widget.onThumbnailLoadingComplete!();
}
},
);

final fixedTrimViewer = FixedTrimViewer(
Expand All @@ -236,6 +250,11 @@ class _TrimViewerState extends State<TrimViewer> with TickerProviderStateMixin {
thumbnailQuality: widget.areaProperties.thumbnailQuality,
borderRadius: widget.areaProperties.borderRadius,
),
onThumbnailLoadingComplete: () {
if (widget.onThumbnailLoadingComplete != null) {
widget.onThumbnailLoadingComplete!();
}
},
);

return _isScrollableAllowed == null
Expand Down

0 comments on commit a08b933

Please sign in to comment.