@@ -292,6 +292,8 @@ - (void)testSeekToWhilePausedStartsDisplayLinkTemporarily {
292
292
StubFVPDisplayLinkFactory *stubDisplayLinkFactory =
293
293
[[StubFVPDisplayLinkFactory alloc ] initWithDisplayLink: mockDisplayLink];
294
294
AVPlayerItemVideoOutput *mockVideoOutput = OCMPartialMock ([[AVPlayerItemVideoOutput alloc ] init ]);
295
+ // Display link and frame updater wire-up is currently done in FVPVideoPlayerPlugin, so create
296
+ // the player via the plugin instead of directly to include that logic in the test.
295
297
FVPVideoPlayerPlugin *videoPlayerPlugin = [[FVPVideoPlayerPlugin alloc ]
296
298
initWithAVFactory: [[StubFVPAVFactory alloc ] initWithPlayer: nil output: mockVideoOutput]
297
299
displayLinkFactory: stubDisplayLinkFactory
@@ -310,8 +312,6 @@ - (void)testSeekToWhilePausedStartsDisplayLinkTemporarily {
310
312
viewType: FVPPlatformVideoViewTypeTextureView];
311
313
FlutterError *createError;
312
314
NSNumber *playerIdentifier = [videoPlayerPlugin createWithOptions: create error: &createError];
313
-
314
- // TODO(stuartmorgan): Rework this test to only create the player, not the whole plugin.
315
315
FVPTextureBasedVideoPlayer *player =
316
316
(FVPTextureBasedVideoPlayer *)videoPlayerPlugin.playersByIdentifier [playerIdentifier];
317
317
@@ -411,6 +411,8 @@ - (void)testSeekToWhilePlayingDoesNotStopDisplayLink {
411
411
StubFVPDisplayLinkFactory *stubDisplayLinkFactory =
412
412
[[StubFVPDisplayLinkFactory alloc ] initWithDisplayLink: mockDisplayLink];
413
413
AVPlayerItemVideoOutput *mockVideoOutput = OCMPartialMock ([[AVPlayerItemVideoOutput alloc ] init ]);
414
+ // Display link and frame updater wire-up is currently done in FVPVideoPlayerPlugin, so create
415
+ // the player via the plugin instead of directly to include that logic in the test.
414
416
FVPVideoPlayerPlugin *videoPlayerPlugin = [[FVPVideoPlayerPlugin alloc ]
415
417
initWithAVFactory: [[StubFVPAVFactory alloc ] initWithPlayer: nil output: mockVideoOutput]
416
418
displayLinkFactory: stubDisplayLinkFactory
@@ -429,8 +431,6 @@ - (void)testSeekToWhilePlayingDoesNotStopDisplayLink {
429
431
viewType: FVPPlatformVideoViewTypeTextureView];
430
432
FlutterError *createError;
431
433
NSNumber *playerIdentifier = [videoPlayerPlugin createWithOptions: create error: &createError];
432
-
433
- // TODO(stuartmorgan): Rework this test to only create the player, not the whole plugin.
434
434
FVPTextureBasedVideoPlayer *player =
435
435
(FVPTextureBasedVideoPlayer *)videoPlayerPlugin.playersByIdentifier [playerIdentifier];
436
436
@@ -474,6 +474,8 @@ - (void)testPauseWhileWaitingForFrameDoesNotStopDisplayLink {
474
474
StubFVPDisplayLinkFactory *stubDisplayLinkFactory =
475
475
[[StubFVPDisplayLinkFactory alloc ] initWithDisplayLink: mockDisplayLink];
476
476
AVPlayerItemVideoOutput *mockVideoOutput = OCMPartialMock ([[AVPlayerItemVideoOutput alloc ] init ]);
477
+ // Display link and frame updater wire-up is currently done in FVPVideoPlayerPlugin, so create
478
+ // the player via the plugin instead of directly to include that logic in the test.
477
479
FVPVideoPlayerPlugin *videoPlayerPlugin = [[FVPVideoPlayerPlugin alloc ]
478
480
initWithAVFactory: [[StubFVPAVFactory alloc ] initWithPlayer: nil output: mockVideoOutput]
479
481
displayLinkFactory: stubDisplayLinkFactory
@@ -492,8 +494,6 @@ - (void)testPauseWhileWaitingForFrameDoesNotStopDisplayLink {
492
494
viewType: FVPPlatformVideoViewTypeTextureView];
493
495
FlutterError *createError;
494
496
NSNumber *playerIdentifier = [videoPlayerPlugin createWithOptions: create error: &createError];
495
-
496
- // TODO(stuartmorgan): Rework this test to only create the player, not the whole plugin.
497
497
FVPTextureBasedVideoPlayer *player =
498
498
(FVPTextureBasedVideoPlayer *)videoPlayerPlugin.playersByIdentifier [playerIdentifier];
499
499
@@ -583,59 +583,36 @@ - (void)testBufferingStateFromPlayer {
583
583
}
584
584
585
585
- (void )testVideoControls {
586
- NSObject <FlutterPluginRegistrar> *registrar = OCMProtocolMock (@protocol (FlutterPluginRegistrar));
587
-
588
- FVPVideoPlayerPlugin *videoPlayerPlugin =
589
- (FVPVideoPlayerPlugin *)[[FVPVideoPlayerPlugin alloc ] initWithRegistrar: registrar];
590
-
591
586
NSDictionary <NSString *, id > *videoInitialization =
592
- [self testPlugin: videoPlayerPlugin
593
- uri: @" https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4" ];
587
+ [self sanityTestURI: @" https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4" ];
594
588
XCTAssertEqualObjects (videoInitialization[@" height" ], @720 );
595
589
XCTAssertEqualObjects (videoInitialization[@" width" ], @1280 );
596
590
XCTAssertEqualWithAccuracy ([videoInitialization[@" duration" ] intValue ], 4000 , 200 );
597
591
}
598
592
599
593
- (void )testAudioControls {
600
- NSObject <FlutterPluginRegistrar> *registrar = OCMProtocolMock (@protocol (FlutterPluginRegistrar));
601
-
602
- FVPVideoPlayerPlugin *videoPlayerPlugin =
603
- (FVPVideoPlayerPlugin *)[[FVPVideoPlayerPlugin alloc ] initWithRegistrar: registrar];
604
-
605
- NSDictionary <NSString *, id > *audioInitialization =
606
- [self testPlugin: videoPlayerPlugin
607
- uri: @" https://flutter.github.io/assets-for-api-docs/assets/audio/rooster.mp3" ];
594
+ NSDictionary <NSString *, id > *audioInitialization = [self
595
+ sanityTestURI: @" https://flutter.github.io/assets-for-api-docs/assets/audio/rooster.mp3" ];
608
596
XCTAssertEqualObjects (audioInitialization[@" height" ], @0 );
609
597
XCTAssertEqualObjects (audioInitialization[@" width" ], @0 );
610
598
// Perfect precision not guaranteed.
611
599
XCTAssertEqualWithAccuracy ([audioInitialization[@" duration" ] intValue ], 5400 , 200 );
612
600
}
613
601
614
602
- (void )testHLSControls {
615
- NSObject <FlutterPluginRegistrar> *registrar = OCMProtocolMock (@protocol (FlutterPluginRegistrar));
616
-
617
- FVPVideoPlayerPlugin *videoPlayerPlugin =
618
- (FVPVideoPlayerPlugin *)[[FVPVideoPlayerPlugin alloc ] initWithRegistrar: registrar];
619
-
620
- NSDictionary <NSString *, id > *videoInitialization =
621
- [self testPlugin: videoPlayerPlugin
622
- uri: @" https://flutter.github.io/assets-for-api-docs/assets/videos/hls/bee.m3u8" ];
603
+ NSDictionary <NSString *, id > *videoInitialization = [self
604
+ sanityTestURI: @" https://flutter.github.io/assets-for-api-docs/assets/videos/hls/bee.m3u8" ];
623
605
XCTAssertEqualObjects (videoInitialization[@" height" ], @720 );
624
606
XCTAssertEqualObjects (videoInitialization[@" width" ], @1280 );
625
607
XCTAssertEqualWithAccuracy ([videoInitialization[@" duration" ] intValue ], 4000 , 200 );
626
608
}
627
609
628
610
- (void )testAudioOnlyHLSControls {
629
611
XCTSkip (@" Flaky; see https://github.com/flutter/flutter/issues/164381" );
630
- NSObject <FlutterPluginRegistrar> *registrar = OCMProtocolMock (@protocol (FlutterPluginRegistrar));
631
-
632
- FVPVideoPlayerPlugin *videoPlayerPlugin =
633
- (FVPVideoPlayerPlugin *)[[FVPVideoPlayerPlugin alloc ] initWithRegistrar: registrar];
634
612
635
613
NSDictionary <NSString *, id > *videoInitialization =
636
- [self testPlugin: videoPlayerPlugin
637
- uri: @" https://flutter.github.io/assets-for-api-docs/assets/videos/hls/"
638
- @" bee_audio_only.m3u8" ];
614
+ [self sanityTestURI: @" https://flutter.github.io/assets-for-api-docs/assets/videos/hls/"
615
+ @" bee_audio_only.m3u8" ];
639
616
XCTAssertEqualObjects (videoInitialization[@" height" ], @0 );
640
617
XCTAssertEqualObjects (videoInitialization[@" width" ], @0 );
641
618
XCTAssertEqualWithAccuracy ([videoInitialization[@" duration" ] intValue ], 4000 , 200 );
@@ -655,40 +632,22 @@ - (void)testTransformFix {
655
632
#endif
656
633
657
634
- (void )testSeekToleranceWhenNotSeekingToEnd {
658
- NSObject <FlutterPluginRegistrar> *registrar = OCMProtocolMock (@protocol (FlutterPluginRegistrar));
659
-
660
635
StubAVPlayer *stubAVPlayer = [[StubAVPlayer alloc ] init ];
661
636
StubFVPAVFactory *stubAVFactory = [[StubFVPAVFactory alloc ] initWithPlayer: stubAVPlayer
662
637
output: nil ];
663
- FVPVideoPlayerPlugin *pluginWithMockAVPlayer =
664
- [[FVPVideoPlayerPlugin alloc ] initWithAVFactory: stubAVFactory
665
- displayLinkFactory: nil
666
- viewProvider: [[StubViewProvider alloc ] initWithView: nil ]
667
- registrar: registrar];
668
-
669
- FlutterError *initializationError;
670
- [pluginWithMockAVPlayer initialize: &initializationError];
671
- XCTAssertNil (initializationError);
672
-
673
- FVPCreationOptions *create = [FVPCreationOptions
674
- makeWithAsset: nil
675
- uri: @" https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4"
676
- packageName: nil
677
- formatHint: nil
678
- httpHeaders: @{}
679
- viewType: FVPPlatformVideoViewTypeTextureView];
680
- FlutterError *createError;
681
- NSNumber *playerIdentifier = [pluginWithMockAVPlayer createWithOptions: create error: &createError];
682
-
683
- // TODO(stuartmorgan): Rework this test to only create the player, not the whole plugin.
684
- FVPTextureBasedVideoPlayer *player =
685
- (FVPTextureBasedVideoPlayer *)pluginWithMockAVPlayer.playersByIdentifier [playerIdentifier];
686
-
687
- XCTestExpectation *initializedExpectation =
638
+ FVPVideoPlayer *player = [[FVPVideoPlayer alloc ]
639
+ initWithURL:
640
+ [NSURL
641
+ URLWithString: @" https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4" ]
642
+ httpHeaders: @{}
643
+ avFactory: stubAVFactory
644
+ viewProvider: [[StubViewProvider alloc ] initWithView: nil ]];
645
+
646
+ XCTestExpectation *seekExpectation =
688
647
[self expectationWithDescription: @" seekTo has zero tolerance when seeking not to end" ];
689
648
[player seekTo: 1234
690
649
completion: ^(FlutterError *_Nullable error) {
691
- [initializedExpectation fulfill ];
650
+ [seekExpectation fulfill ];
692
651
}];
693
652
694
653
[self waitForExpectationsWithTimeout: 30.0 handler: nil ];
@@ -697,64 +656,37 @@ - (void)testSeekToleranceWhenNotSeekingToEnd {
697
656
}
698
657
699
658
- (void )testSeekToleranceWhenSeekingToEnd {
700
- NSObject <FlutterPluginRegistrar> *registrar = OCMProtocolMock (@protocol (FlutterPluginRegistrar));
701
-
702
659
StubAVPlayer *stubAVPlayer = [[StubAVPlayer alloc ] init ];
703
660
StubFVPAVFactory *stubAVFactory = [[StubFVPAVFactory alloc ] initWithPlayer: stubAVPlayer
704
661
output: nil ];
705
- FVPVideoPlayerPlugin *pluginWithMockAVPlayer =
706
- [[FVPVideoPlayerPlugin alloc ] initWithAVFactory: stubAVFactory
707
- displayLinkFactory: nil
708
- viewProvider: [[StubViewProvider alloc ] initWithView: nil ]
709
- registrar: registrar];
710
-
711
- FlutterError *initializationError;
712
- [pluginWithMockAVPlayer initialize: &initializationError];
713
- XCTAssertNil (initializationError);
714
-
715
- FVPCreationOptions *create = [FVPCreationOptions
716
- makeWithAsset: nil
717
- uri: @" https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4"
718
- packageName: nil
719
- formatHint: nil
720
- httpHeaders: @{}
721
- viewType: FVPPlatformVideoViewTypeTextureView];
722
- FlutterError *createError;
723
- NSNumber *playerIdentifier = [pluginWithMockAVPlayer createWithOptions: create error: &createError];
724
-
725
- // TODO(stuartmorgan): Rework this test to only create the player, not the whole plugin.
726
- FVPTextureBasedVideoPlayer *player =
727
- (FVPTextureBasedVideoPlayer *)pluginWithMockAVPlayer.playersByIdentifier [playerIdentifier];
728
-
729
- XCTestExpectation *initializedExpectation =
662
+ FVPVideoPlayer *player = [[FVPVideoPlayer alloc ]
663
+ initWithURL:
664
+ [NSURL
665
+ URLWithString: @" https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4" ]
666
+ httpHeaders: @{}
667
+ avFactory: stubAVFactory
668
+ viewProvider: [[StubViewProvider alloc ] initWithView: nil ]];
669
+
670
+ XCTestExpectation *seekExpectation =
730
671
[self expectationWithDescription: @" seekTo has non-zero tolerance when seeking to end" ];
731
672
// The duration of this video is "0" due to the non standard initiliatazion process.
732
673
[player seekTo: 0
733
674
completion: ^(FlutterError *_Nullable error) {
734
- [initializedExpectation fulfill ];
675
+ [seekExpectation fulfill ];
735
676
}];
736
677
[self waitForExpectationsWithTimeout: 30.0 handler: nil ];
737
678
XCTAssertGreaterThan ([stubAVPlayer.beforeTolerance intValue ], 0 );
738
679
XCTAssertGreaterThan ([stubAVPlayer.afterTolerance intValue ], 0 );
739
680
}
740
681
741
- - (NSDictionary <NSString *, id> *)testPlugin : (FVPVideoPlayerPlugin *)videoPlayerPlugin
742
- uri : (NSString *)uri {
743
- FlutterError *error;
744
- [videoPlayerPlugin initialize: &error];
745
- XCTAssertNil (error);
746
-
747
- FVPCreationOptions *create =
748
- [FVPCreationOptions makeWithAsset: nil
749
- uri: uri
750
- packageName: nil
751
- formatHint: nil
752
- httpHeaders: @{}
753
- viewType: FVPPlatformVideoViewTypeTextureView];
754
- NSNumber *playerIdentifier = [videoPlayerPlugin createWithOptions: create error: &error];
755
-
756
- // TODO(stuartmorgan): Rework this test to only create the player, not the whole plugin.
757
- FVPVideoPlayer *player = videoPlayerPlugin.playersByIdentifier [playerIdentifier];
682
+ // / Sanity checks a video player playing the given URL with the actual AVPlayer. This is essentially
683
+ // / a mini integration test of the player component.
684
+ - (NSDictionary <NSString *, id> *)sanityTestURI : (NSString *)uri {
685
+ FVPVideoPlayer *player =
686
+ [[FVPVideoPlayer alloc ] initWithURL: [NSURL URLWithString: uri]
687
+ httpHeaders: @{}
688
+ avFactory: [[FVPDefaultAVFactory alloc ] init ]
689
+ viewProvider: [[StubViewProvider alloc ] initWithView: nil ]];
758
690
XCTAssertNotNil (player);
759
691
760
692
XCTestExpectation *initializedExpectation = [self expectationWithDescription: @" initialized" ];
@@ -776,6 +708,7 @@ - (void)testSeekToleranceWhenSeekingToEnd {
776
708
XCTAssertEqual (avPlayer.timeControlStatus , AVPlayerTimeControlStatusPaused);
777
709
778
710
// Change playback speed.
711
+ FlutterError *error;
779
712
[player setPlaybackSpeed: 2 error: &error];
780
713
XCTAssertNil (error);
781
714
[player playWithError: &error];
@@ -963,27 +896,13 @@ - (void)testFailedToLoadVideoEventShouldBeAlwaysSent {
963
896
}
964
897
965
898
- (void )testUpdatePlayingStateShouldNotResetRate {
966
- NSObject <FlutterPluginRegistrar> *registrar = OCMProtocolMock (@protocol (FlutterPluginRegistrar));
967
-
968
- FVPVideoPlayerPlugin *videoPlayerPlugin = [[FVPVideoPlayerPlugin alloc ]
969
- initWithAVFactory: [[StubFVPAVFactory alloc ] initWithPlayer: nil output: nil ]
970
- displayLinkFactory: nil
971
- viewProvider: [[StubViewProvider alloc ] initWithView: nil ]
972
- registrar: registrar];
973
-
974
- FlutterError *error;
975
- [videoPlayerPlugin initialize: &error];
976
- XCTAssertNil (error);
977
- FVPCreationOptions *create = [FVPCreationOptions
978
- makeWithAsset: nil
979
- uri: @" https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4"
980
- packageName: nil
981
- formatHint: nil
982
- httpHeaders: @{}
983
- viewType: FVPPlatformVideoViewTypeTextureView];
984
- NSNumber *playerIdentifier = [videoPlayerPlugin createWithOptions: create error: &error];
985
- // TODO(stuartmorgan): Rework this test to only create the player, not the whole plugin.
986
- FVPVideoPlayer *player = videoPlayerPlugin.playersByIdentifier [playerIdentifier];
899
+ FVPVideoPlayer *player = [[FVPVideoPlayer alloc ]
900
+ initWithURL:
901
+ [NSURL
902
+ URLWithString: @" https://flutter.github.io/assets-for-api-docs/assets/videos/bee.mp4" ]
903
+ httpHeaders: @{}
904
+ avFactory: [[StubFVPAVFactory alloc ] initWithPlayer: nil output: nil ]
905
+ viewProvider: [[StubViewProvider alloc ] initWithView: nil ]];
987
906
988
907
XCTestExpectation *initializedExpectation = [self expectationWithDescription: @" initialized" ];
989
908
[player onListenWithArguments: nil
@@ -994,6 +913,7 @@ - (void)testUpdatePlayingStateShouldNotResetRate {
994
913
}];
995
914
[self waitForExpectationsWithTimeout: 10 handler: nil ];
996
915
916
+ FlutterError *error;
997
917
[player setPlaybackSpeed: 2 error: &error];
998
918
[player playWithError: &error];
999
919
XCTAssertEqual (player.player .rate , 2 );
0 commit comments