Skip to content

Commit 37b592c

Browse files
authored
[video_player] Wait to initialize m3u8 videos on iOS until size is set (flutter#4727)
1 parent 4d92d90 commit 37b592c

File tree

6 files changed

+28
-7
lines changed

6 files changed

+28
-7
lines changed

packages/video_player/video_player_avfoundation/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
## NEXT
1+
## 2.2.18
22

3+
* Wait to initialize m3u8 videos until size is set, fixing aspect ratio.
34
* Adjusts test timeouts for network-dependent native tests to avoid flake.
45

56
## 2.2.17

packages/video_player/video_player_avfoundation/example/ios/Runner.xcodeproj/project.pbxproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
archiveVersion = 1;
44
classes = {
55
};
6-
objectVersion = 50;
6+
objectVersion = 46;
77
objects = {
88

99
/* Begin PBXBuildFile section */
@@ -269,7 +269,7 @@
269269
97C146E61CF9000F007C117D /* Project object */ = {
270270
isa = PBXProject;
271271
attributes = {
272-
LastUpgradeCheck = 1300;
272+
LastUpgradeCheck = 1320;
273273
ORGANIZATIONNAME = "The Flutter Authors";
274274
TargetAttributes = {
275275
97C146ED1CF9000F007C117D = {

packages/video_player/video_player_avfoundation/example/ios/Runner.xcodeproj/xcshareddata/xcschemes/Runner.xcscheme

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<Scheme
3-
LastUpgradeVersion = "1300"
3+
LastUpgradeVersion = "1320"
44
version = "1.3">
55
<BuildAction
66
parallelizeBuildables = "YES"

packages/video_player/video_player_avfoundation/example/ios/RunnerTests/VideoPlayerTests.m

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,22 @@ - (void)testAudioControls {
103103
XCTAssertEqualWithAccuracy([audioInitialization[@"duration"] intValue], 5400, 200);
104104
}
105105

106+
- (void)testHLSControls {
107+
NSObject<FlutterPluginRegistry> *registry =
108+
(NSObject<FlutterPluginRegistry> *)[[UIApplication sharedApplication] delegate];
109+
NSObject<FlutterPluginRegistrar> *registrar = [registry registrarForPlugin:@"TestHLSControls"];
110+
111+
FLTVideoPlayerPlugin *videoPlayerPlugin =
112+
(FLTVideoPlayerPlugin *)[[FLTVideoPlayerPlugin alloc] initWithRegistrar:registrar];
113+
114+
NSDictionary<NSString *, id> *videoInitialization =
115+
[self testPlugin:videoPlayerPlugin
116+
uri:@"https://flutter.github.io/assets-for-api-docs/assets/videos/hls/bee.m3u8"];
117+
XCTAssertEqualObjects(videoInitialization[@"height"], @720);
118+
XCTAssertEqualObjects(videoInitialization[@"width"], @1280);
119+
XCTAssertEqualWithAccuracy([videoInitialization[@"duration"] intValue], 4000, 200);
120+
}
121+
106122
- (NSDictionary<NSString *, id> *)testPlugin:(FLTVideoPlayerPlugin *)videoPlayerPlugin
107123
uri:(NSString *)uri {
108124
FlutterError *error;

packages/video_player/video_player_avfoundation/ios/Classes/FLTVideoPlayerPlugin.m

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,9 +354,13 @@ - (void)setupEventSinkIfReadyToPlay {
354354
}
355355

356356
BOOL hasVideoTracks = [asset tracksWithMediaType:AVMediaTypeVideo].count != 0;
357+
BOOL hasNoTracks = asset.tracks.count == 0;
357358

358-
// The player has not yet initialized when it contains video tracks.
359-
if (hasVideoTracks && height == CGSizeZero.height && width == CGSizeZero.width) {
359+
// The player has not yet initialized when it has no size, unless it is an audio-only track.
360+
// HLS m3u8 video files never load any tracks, and are also not yet initialized until they have
361+
// a size.
362+
if ((hasVideoTracks || hasNoTracks) && height == CGSizeZero.height &&
363+
width == CGSizeZero.width) {
360364
return;
361365
}
362366
// The player may be initialized but still needs to determine the duration.

packages/video_player/video_player_avfoundation/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: video_player_avfoundation
22
description: iOS implementation of the video_player plugin.
33
repository: https://github.com/flutter/plugins/tree/master/packages/video_player/video_player_avfoundation
44
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
5-
version: 2.2.17
5+
version: 2.2.18
66

77
environment:
88
sdk: ">=2.14.0 <3.0.0"

0 commit comments

Comments
 (0)