diff --git a/packages/video_player/video_player_avfoundation/CHANGELOG.md b/packages/video_player/video_player_avfoundation/CHANGELOG.md index 7f509fcc462..da8e640a8c5 100644 --- a/packages/video_player/video_player_avfoundation/CHANGELOG.md +++ b/packages/video_player/video_player_avfoundation/CHANGELOG.md @@ -1,3 +1,8 @@ +## 2.8.9 + +* Improves compatibility with `UIScene`. +* Updates minimum supported SDK version to Flutter 3.38/Dart 3.10. + ## 2.8.8 * Refactors Dart internals for maintainability. diff --git a/packages/video_player/video_player_avfoundation/darwin/RunnerTests/VideoPlayerTests.m b/packages/video_player/video_player_avfoundation/darwin/RunnerTests/VideoPlayerTests.m index b095dbf33ae..ee27930fafa 100644 --- a/packages/video_player/video_player_avfoundation/darwin/RunnerTests/VideoPlayerTests.m +++ b/packages/video_player/video_player_avfoundation/darwin/RunnerTests/VideoPlayerTests.m @@ -79,24 +79,30 @@ - (void)seekToTime:(CMTime)time @end -// Convience to avoid having two copies of the StubViewProvider code. -#if TARGET_OS_OSX -#define PROVIDED_VIEW_TYPE NSView +@interface StubViewProvider : NSObject +#if TARGET_OS_IOS +- (instancetype)initWithViewController:(UIViewController *)viewController; +@property(nonatomic, nullable) UIViewController *viewController; #else -#define PROVIDED_VIEW_TYPE UIView +- (instancetype)initWithView:(NSView *)view; +@property(nonatomic, nullable) NSView *view; #endif - -@interface StubViewProvider : NSObject -- (instancetype)initWithView:(PROVIDED_VIEW_TYPE *)view; -@property(nonatomic, nullable) PROVIDED_VIEW_TYPE *view; @end @implementation StubViewProvider -- (instancetype)initWithView:(PROVIDED_VIEW_TYPE *)view { +#if TARGET_OS_IOS +- (instancetype)initWithViewController:(UIViewController *)viewController { + self = [super init]; + _viewController = viewController; + return self; +} +#else +- (instancetype)initWithView:(NSView *)view { self = [super init]; _view = view; return self; } +#endif @end @interface StubFVPAVFactory : NSObject @@ -227,14 +233,19 @@ - (void)testBlankVideoBugWithEncryptedVideoStreamAndInvertedAspectRatioBugForSom #if TARGET_OS_OSX NSView *view = [[NSView alloc] initWithFrame:NSMakeRect(0, 0, 10, 10)]; view.wantsLayer = true; + id viewProvider = [[StubViewProvider alloc] initWithView:view]; #else UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 10, 10)]; + UIViewController *viewController = [[UIViewController alloc] init]; + viewController.view = view; + id viewProvider = + [[StubViewProvider alloc] initWithViewController:viewController]; #endif NSObject *registrar = OCMProtocolMock(@protocol(FlutterPluginRegistrar)); FVPVideoPlayerPlugin *videoPlayerPlugin = [[FVPVideoPlayerPlugin alloc] initWithAVFactory:[[StubFVPAVFactory alloc] initWithPlayer:nil output:nil] displayLinkFactory:nil - viewProvider:[[StubViewProvider alloc] initWithView:view] + viewProvider:viewProvider registrar:registrar]; FlutterError *error; @@ -267,7 +278,7 @@ - (void)testPlayerForPlatformViewDoesNotRegisterTexture { FVPVideoPlayerPlugin *videoPlayerPlugin = [[FVPVideoPlayerPlugin alloc] initWithAVFactory:[[StubFVPAVFactory alloc] initWithPlayer:nil output:mockVideoOutput] displayLinkFactory:stubDisplayLinkFactory - viewProvider:[[StubViewProvider alloc] initWithView:nil] + viewProvider:[[StubViewProvider alloc] init] registrar:registrar]; FlutterError *initializationError; @@ -294,7 +305,7 @@ - (void)testSeekToWhilePausedStartsDisplayLinkTemporarily { FVPVideoPlayerPlugin *videoPlayerPlugin = [[FVPVideoPlayerPlugin alloc] initWithAVFactory:[[StubFVPAVFactory alloc] initWithPlayer:nil output:mockVideoOutput] displayLinkFactory:stubDisplayLinkFactory - viewProvider:[[StubViewProvider alloc] initWithView:nil] + viewProvider:[[StubViewProvider alloc] init] registrar:registrar]; FlutterError *initializationError; @@ -351,7 +362,7 @@ - (void)testInitStartsDisplayLinkTemporarily { initWithAVFactory:[[StubFVPAVFactory alloc] initWithPlayer:stubAVPlayer output:mockVideoOutput] displayLinkFactory:stubDisplayLinkFactory - viewProvider:[[StubViewProvider alloc] initWithView:nil] + viewProvider:[[StubViewProvider alloc] init] registrar:registrar]; FlutterError *initializationError; @@ -397,7 +408,7 @@ - (void)testSeekToWhilePlayingDoesNotStopDisplayLink { FVPVideoPlayerPlugin *videoPlayerPlugin = [[FVPVideoPlayerPlugin alloc] initWithAVFactory:[[StubFVPAVFactory alloc] initWithPlayer:nil output:mockVideoOutput] displayLinkFactory:stubDisplayLinkFactory - viewProvider:[[StubViewProvider alloc] initWithView:nil] + viewProvider:[[StubViewProvider alloc] init] registrar:registrar]; FlutterError *initializationError; @@ -452,7 +463,7 @@ - (void)testPauseWhileWaitingForFrameDoesNotStopDisplayLink { FVPVideoPlayerPlugin *videoPlayerPlugin = [[FVPVideoPlayerPlugin alloc] initWithAVFactory:[[StubFVPAVFactory alloc] initWithPlayer:nil output:mockVideoOutput] displayLinkFactory:stubDisplayLinkFactory - viewProvider:[[StubViewProvider alloc] initWithView:nil] + viewProvider:[[StubViewProvider alloc] init] registrar:registrar]; FlutterError *initializationError; @@ -605,7 +616,7 @@ - (void)testSeekToleranceWhenNotSeekingToEnd { FVPVideoPlayer *player = [[FVPVideoPlayer alloc] initWithPlayerItem:[self playerItemWithURL:self.mp4TestURL] avFactory:stubAVFactory - viewProvider:[[StubViewProvider alloc] initWithView:nil]]; + viewProvider:[[StubViewProvider alloc] init]]; NSObject *listener = OCMProtocolMock(@protocol(FVPVideoEventListener)); player.eventListener = listener; @@ -628,7 +639,7 @@ - (void)testSeekToleranceWhenSeekingToEnd { FVPVideoPlayer *player = [[FVPVideoPlayer alloc] initWithPlayerItem:[self playerItemWithURL:self.mp4TestURL] avFactory:stubAVFactory - viewProvider:[[StubViewProvider alloc] initWithView:nil]]; + viewProvider:[[StubViewProvider alloc] init]]; NSObject *listener = OCMProtocolMock(@protocol(FVPVideoEventListener)); player.eventListener = listener; @@ -654,7 +665,7 @@ - (StubEventListener *)sanityTestURI:(NSString *)testURI { FVPVideoPlayer *player = [[FVPVideoPlayer alloc] initWithPlayerItem:[self playerItemWithURL:testURL] avFactory:[[FVPDefaultAVFactory alloc] init] - viewProvider:[[StubViewProvider alloc] initWithView:nil]]; + viewProvider:[[StubViewProvider alloc] init]]; XCTAssertNotNil(player); XCTestExpectation *initializedExpectation = [self expectationWithDescription:@"initialized"]; @@ -850,7 +861,7 @@ - (void)testUpdatePlayingStateShouldNotResetRate { FVPVideoPlayer *player = [[FVPVideoPlayer alloc] initWithPlayerItem:[self playerItemWithURL:self.mp4TestURL] avFactory:[[StubFVPAVFactory alloc] initWithPlayer:nil output:nil] - viewProvider:[[StubViewProvider alloc] initWithView:nil]]; + viewProvider:[[StubViewProvider alloc] init]]; XCTestExpectation *initializedExpectation = [self expectationWithDescription:@"initialized"]; StubEventListener *listener = @@ -875,7 +886,7 @@ - (void)testPlayerShouldNotDropEverySecondFrame { FVPVideoPlayerPlugin *videoPlayerPlugin = [[FVPVideoPlayerPlugin alloc] initWithAVFactory:[[StubFVPAVFactory alloc] initWithPlayer:nil output:mockVideoOutput] displayLinkFactory:stubDisplayLinkFactory - viewProvider:[[StubViewProvider alloc] initWithView:nil] + viewProvider:[[StubViewProvider alloc] init] registrar:registrar]; FlutterError *error; diff --git a/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/FVPTextureBasedVideoPlayer.m b/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/FVPTextureBasedVideoPlayer.m index 8fd7e1dd2f3..9bad19db91c 100644 --- a/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/FVPTextureBasedVideoPlayer.m +++ b/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/FVPTextureBasedVideoPlayer.m @@ -54,7 +54,12 @@ - (instancetype)initWithPlayerItem:(AVPlayerItem *)item // invisible AVPlayerLayer is used to overwrite the protection of pixel buffers in those streams // for issue #1, and restore the correct width and height for issue #2. _playerLayer = [AVPlayerLayer playerLayerWithPlayer:self.player]; - [viewProvider.view.layer addSublayer:self.playerLayer]; +#if TARGET_OS_IOS + CALayer *flutterLayer = viewProvider.viewController.view.layer; +#else + CALayer *flutterLayer = viewProvider.view.layer; +#endif + [flutterLayer addSublayer:self.playerLayer]; } return self; } diff --git a/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/FVPViewProvider.m b/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/FVPViewProvider.m index b824ae16a7a..d1f6ec96eac 100644 --- a/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/FVPViewProvider.m +++ b/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/FVPViewProvider.m @@ -29,14 +29,8 @@ - (NSView *)view { return self.registrar.view; } #else -- (UIView *)view { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wdeprecated-declarations" - // TODO(hellohuanlin): Provide a non-deprecated codepath. See - // https://github.com/flutter/flutter/issues/104117 - UIViewController *root = UIApplication.sharedApplication.keyWindow.rootViewController; -#pragma clang diagnostic pop - return root.view; +- (UIViewController *)viewController { + return self.registrar.viewController; } #endif @end diff --git a/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/include/video_player_avfoundation/FVPViewProvider.h b/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/include/video_player_avfoundation/FVPViewProvider.h index 8fba4565d3c..88689025d49 100644 --- a/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/include/video_player_avfoundation/FVPViewProvider.h +++ b/packages/video_player/video_player_avfoundation/darwin/video_player_avfoundation/Sources/video_player_avfoundation/include/video_player_avfoundation/FVPViewProvider.h @@ -19,8 +19,8 @@ NS_ASSUME_NONNULL_BEGIN /// The view containing the Flutter content. @property(nonatomic, readonly, nullable) NSView *view; #else -/// The view containing the Flutter content. -@property(nonatomic, readonly, nullable) UIView *view; +/// The view controller containing the Flutter content. +@property(nonatomic, readonly, nullable) UIViewController *viewController; #endif @end diff --git a/packages/video_player/video_player_avfoundation/example/pubspec.yaml b/packages/video_player/video_player_avfoundation/example/pubspec.yaml index cc176e75c3f..78f1b144f94 100644 --- a/packages/video_player/video_player_avfoundation/example/pubspec.yaml +++ b/packages/video_player/video_player_avfoundation/example/pubspec.yaml @@ -3,8 +3,8 @@ description: Demonstrates how to use the video_player plugin. publish_to: none environment: - sdk: ^3.9.0 - flutter: ">=3.35.0" + sdk: ^3.10.0 + flutter: ">=3.38.0" dependencies: flutter: diff --git a/packages/video_player/video_player_avfoundation/pubspec.yaml b/packages/video_player/video_player_avfoundation/pubspec.yaml index 9c326136d92..8b7258f556a 100644 --- a/packages/video_player/video_player_avfoundation/pubspec.yaml +++ b/packages/video_player/video_player_avfoundation/pubspec.yaml @@ -2,11 +2,11 @@ name: video_player_avfoundation description: iOS and macOS implementation of the video_player plugin. repository: https://github.com/flutter/packages/tree/main/packages/video_player/video_player_avfoundation issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22 -version: 2.8.8 +version: 2.8.9 environment: - sdk: ^3.9.0 - flutter: ">=3.35.0" + sdk: ^3.10.0 + flutter: ">=3.38.0" flutter: plugin: