@@ -69,6 +69,9 @@ class FakeController extends ValueNotifier<VideoPlayerValue>
6969
7070 @override
7171 VideoPlayerOptions ? get videoPlayerOptions => null ;
72+
73+ @override
74+ void setCaptionOffset (Duration delay) {}
7275}
7376
7477Future <ClosedCaptionFile > _loadClosedCaption () async =>
@@ -557,11 +560,92 @@ void main() {
557560 await controller.seekTo (const Duration (milliseconds: 300 ));
558561 expect (controller.value.caption.text, 'two' );
559562
563+ await controller.seekTo (const Duration (milliseconds: 301 ));
564+ expect (controller.value.caption.text, 'two' );
565+
566+ await controller.seekTo (const Duration (milliseconds: 500 ));
567+ expect (controller.value.caption.text, '' );
568+
569+ await controller.seekTo (const Duration (milliseconds: 300 ));
570+ expect (controller.value.caption.text, 'two' );
571+
572+ await controller.seekTo (const Duration (milliseconds: 301 ));
573+ expect (controller.value.caption.text, 'two' );
574+ });
575+
576+ test ('works when seeking with captionOffset positive' , () async {
577+ final VideoPlayerController controller = VideoPlayerController .network (
578+ 'https://127.0.0.1' ,
579+ closedCaptionFile: _loadClosedCaption (),
580+ );
581+
582+ await controller.initialize ();
583+ controller.setCaptionOffset (Duration (milliseconds: 100 ));
584+ expect (controller.value.position, const Duration ());
585+ expect (controller.value.caption.text, '' );
586+
587+ await controller.seekTo (const Duration (milliseconds: 100 ));
588+ expect (controller.value.caption.text, 'one' );
589+
590+ await controller.seekTo (const Duration (milliseconds: 101 ));
591+ expect (controller.value.caption.text, '' );
592+
593+ await controller.seekTo (const Duration (milliseconds: 250 ));
594+ expect (controller.value.caption.text, 'two' );
595+
596+ await controller.seekTo (const Duration (milliseconds: 300 ));
597+ expect (controller.value.caption.text, 'two' );
598+
599+ await controller.seekTo (const Duration (milliseconds: 301 ));
600+ expect (controller.value.caption.text, '' );
601+
560602 await controller.seekTo (const Duration (milliseconds: 500 ));
561603 expect (controller.value.caption.text, '' );
562604
563605 await controller.seekTo (const Duration (milliseconds: 300 ));
564606 expect (controller.value.caption.text, 'two' );
607+
608+ await controller.seekTo (const Duration (milliseconds: 301 ));
609+ expect (controller.value.caption.text, '' );
610+ });
611+
612+ test ('works when seeking with captionOffset negative' , () async {
613+ final VideoPlayerController controller = VideoPlayerController .network (
614+ 'https://127.0.0.1' ,
615+ closedCaptionFile: _loadClosedCaption (),
616+ );
617+
618+ await controller.initialize ();
619+ controller.setCaptionOffset (Duration (milliseconds: - 100 ));
620+ expect (controller.value.position, const Duration ());
621+ expect (controller.value.caption.text, '' );
622+
623+ await controller.seekTo (const Duration (milliseconds: 100 ));
624+ expect (controller.value.caption.text, '' );
625+
626+ await controller.seekTo (const Duration (milliseconds: 200 ));
627+ expect (controller.value.caption.text, 'one' );
628+
629+ await controller.seekTo (const Duration (milliseconds: 250 ));
630+ expect (controller.value.caption.text, 'one' );
631+
632+ await controller.seekTo (const Duration (milliseconds: 300 ));
633+ expect (controller.value.caption.text, 'one' );
634+
635+ await controller.seekTo (const Duration (milliseconds: 301 ));
636+ expect (controller.value.caption.text, '' );
637+
638+ await controller.seekTo (const Duration (milliseconds: 400 ));
639+ expect (controller.value.caption.text, 'two' );
640+
641+ await controller.seekTo (const Duration (milliseconds: 500 ));
642+ expect (controller.value.caption.text, 'two' );
643+
644+ await controller.seekTo (const Duration (milliseconds: 600 ));
645+ expect (controller.value.caption.text, '' );
646+
647+ await controller.seekTo (const Duration (milliseconds: 300 ));
648+ expect (controller.value.caption.text, 'one' );
565649 });
566650 });
567651
@@ -655,6 +739,7 @@ void main() {
655739 expect (uninitialized.duration, equals (Duration .zero));
656740 expect (uninitialized.position, equals (Duration .zero));
657741 expect (uninitialized.caption, equals (Caption .none));
742+ expect (uninitialized.captionOffset, equals (Duration .zero));
658743 expect (uninitialized.buffered, isEmpty);
659744 expect (uninitialized.isPlaying, isFalse);
660745 expect (uninitialized.isLooping, isFalse);
@@ -675,6 +760,7 @@ void main() {
675760 expect (error.duration, equals (Duration .zero));
676761 expect (error.position, equals (Duration .zero));
677762 expect (error.caption, equals (Caption .none));
763+ expect (error.captionOffset, equals (Duration .zero));
678764 expect (error.buffered, isEmpty);
679765 expect (error.isPlaying, isFalse);
680766 expect (error.isLooping, isFalse);
@@ -694,6 +780,7 @@ void main() {
694780 const Duration position = Duration (seconds: 1 );
695781 const Caption caption = Caption (
696782 text: 'foo' , number: 0 , start: Duration .zero, end: Duration .zero);
783+ const Duration captionOffset = Duration (milliseconds: 250 );
697784 final List <DurationRange > buffered = < DurationRange > [
698785 DurationRange (const Duration (seconds: 0 ), const Duration (seconds: 4 ))
699786 ];
@@ -709,6 +796,7 @@ void main() {
709796 size: size,
710797 position: position,
711798 caption: caption,
799+ captionOffset: captionOffset,
712800 buffered: buffered,
713801 isInitialized: isInitialized,
714802 isPlaying: isPlaying,
@@ -724,6 +812,7 @@ void main() {
724812 'size: Size(400.0, 300.0), '
725813 'position: 0:00:01.000000, '
726814 'caption: Caption(number: 0, start: 0:00:00.000000, end: 0:00:00.000000, text: foo), '
815+ 'captionOffset: 0:00:00.250000, '
727816 'buffered: [DurationRange(start: 0:00:00.000000, end: 0:00:04.000000)], '
728817 'isInitialized: true, '
729818 'isPlaying: true, '
0 commit comments