@@ -69,6 +69,9 @@ class FakeController extends ValueNotifier<VideoPlayerValue>
69
69
70
70
@override
71
71
VideoPlayerOptions ? get videoPlayerOptions => null ;
72
+
73
+ @override
74
+ void setCaptionOffset (Duration delay) {}
72
75
}
73
76
74
77
Future <ClosedCaptionFile > _loadClosedCaption () async =>
@@ -557,11 +560,92 @@ void main() {
557
560
await controller.seekTo (const Duration (milliseconds: 300 ));
558
561
expect (controller.value.caption.text, 'two' );
559
562
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
+
560
602
await controller.seekTo (const Duration (milliseconds: 500 ));
561
603
expect (controller.value.caption.text, '' );
562
604
563
605
await controller.seekTo (const Duration (milliseconds: 300 ));
564
606
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' );
565
649
});
566
650
});
567
651
@@ -655,6 +739,7 @@ void main() {
655
739
expect (uninitialized.duration, equals (Duration .zero));
656
740
expect (uninitialized.position, equals (Duration .zero));
657
741
expect (uninitialized.caption, equals (Caption .none));
742
+ expect (uninitialized.captionOffset, equals (Duration .zero));
658
743
expect (uninitialized.buffered, isEmpty);
659
744
expect (uninitialized.isPlaying, isFalse);
660
745
expect (uninitialized.isLooping, isFalse);
@@ -675,6 +760,7 @@ void main() {
675
760
expect (error.duration, equals (Duration .zero));
676
761
expect (error.position, equals (Duration .zero));
677
762
expect (error.caption, equals (Caption .none));
763
+ expect (error.captionOffset, equals (Duration .zero));
678
764
expect (error.buffered, isEmpty);
679
765
expect (error.isPlaying, isFalse);
680
766
expect (error.isLooping, isFalse);
@@ -694,6 +780,7 @@ void main() {
694
780
const Duration position = Duration (seconds: 1 );
695
781
const Caption caption = Caption (
696
782
text: 'foo' , number: 0 , start: Duration .zero, end: Duration .zero);
783
+ const Duration captionOffset = Duration (milliseconds: 250 );
697
784
final List <DurationRange > buffered = < DurationRange > [
698
785
DurationRange (const Duration (seconds: 0 ), const Duration (seconds: 4 ))
699
786
];
@@ -709,6 +796,7 @@ void main() {
709
796
size: size,
710
797
position: position,
711
798
caption: caption,
799
+ captionOffset: captionOffset,
712
800
buffered: buffered,
713
801
isInitialized: isInitialized,
714
802
isPlaying: isPlaying,
@@ -724,6 +812,7 @@ void main() {
724
812
'size: Size(400.0, 300.0), '
725
813
'position: 0:00:01.000000, '
726
814
'caption: Caption(number: 0, start: 0:00:00.000000, end: 0:00:00.000000, text: foo), '
815
+ 'captionOffset: 0:00:00.250000, '
727
816
'buffered: [DurationRange(start: 0:00:00.000000, end: 0:00:04.000000)], '
728
817
'isInitialized: true, '
729
818
'isPlaying: true, '
0 commit comments