Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/video_player/video_player_avfoundation/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.9.4

* Ensures that the display link does not continue requesting frames after a player is disposed.

## 2.9.3

* Fixes a regression where HTTP headers were ignored.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,29 @@ private let hlsAudioTestURI =
#expect(stubDisplayLinkFactory.displayLink.running)
}

@Test func disposeWhilePlayingStopsDisplayLink() async {
let stubDisplayLinkFactory = StubFVPDisplayLinkFactory()
let mockVideoOutput = TestPixelBufferSource()
let videoPlayerPlugin = createInitializedPlugin(
avFactory: StubFVPAVFactory(pixelBufferSource: mockVideoOutput),
displayLinkFactory: stubDisplayLinkFactory)

var error: FlutterError?
let identifiers = videoPlayerPlugin.createTexturePlayer(
with: FVPCreationOptions.make(withUri: hlsTestURI, httpHeaders: [:]),
error: &error)
#expect(error == nil)
let player =
videoPlayerPlugin.playersByIdentifier[identifiers!.playerId] as! FVPTextureBasedVideoPlayer
Comment on lines +207 to +212
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For improved test robustness, it's better to use try #require to handle the optional returned by createTexturePlayer. This ensures the test fails gracefully with a clear message if nil is returned, rather than crashing due to force-unwrapping.

Suggested change
let identifiers = videoPlayerPlugin.createTexturePlayer(
with: FVPCreationOptions.make(withUri: hlsTestURI, httpHeaders: [:]),
error: &error)
#expect(error == nil)
let player =
videoPlayerPlugin.playersByIdentifier[identifiers!.playerId] as! FVPTextureBasedVideoPlayer
let identifiers = try #require(videoPlayerPlugin.createTexturePlayer(
with: FVPCreationOptions.make(withUri: hlsTestURI, httpHeaders: [:]),
error: &error))
#expect(error == nil)
let player =
videoPlayerPlugin.playersByIdentifier[identifiers.playerId] as! FVPTextureBasedVideoPlayer


player.playWithError(&error)
#expect(error == nil)
player.disposeWithError(&error)
#expect(error == nil)

#expect(!stubDisplayLinkFactory.displayLink.running)
}

@Test func deregistersFromPlayer() throws {
let videoPlayerPlugin = createInitializedPlugin()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ - (void)disposeWithError:(FlutterError *_Nullable *_Nonnull)error {

[self.playerLayer removeFromSuperlayer];

_displayLink.running = NO;
_displayLink = nil;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ 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.9.3
version: 2.9.4

environment:
sdk: ^3.10.0
Expand Down
Loading