Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit d3b39ca

Browse files
committed
[video_player] Initialize player when size and duration become available
1 parent 42364e4 commit d3b39ca

File tree

5 files changed

+50
-14
lines changed

5 files changed

+50
-14
lines changed

packages/video_player/video_player/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.2.6
2+
3+
* Initialize player when size and duration become available on iOS
4+
15
## 2.2.5
26

37
* Support to closed caption WebVTT format added.

packages/video_player/video_player/example/ios/RunnerUITests/VideoPlayerUITests.m

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,46 @@ - (void)setUp {
1818
[self.app launch];
1919
}
2020

21-
- (void)testTabs {
21+
- (void)testPlayVideo {
2222
XCUIApplication* app = self.app;
2323

2424
XCUIElement* remoteTab = [app.otherElements
2525
elementMatchingPredicate:[NSPredicate predicateWithFormat:@"selected == YES"]];
26-
if (![remoteTab waitForExistenceWithTimeout:30.0]) {
27-
os_log_error(OS_LOG_DEFAULT, "%@", app.debugDescription);
28-
XCTFail(@"Failed due to not able to find selected Remote tab");
29-
}
26+
XCTAssertTrue([remoteTab waitForExistenceWithTimeout:30.0]);
3027
XCTAssertTrue([remoteTab.label containsString:@"Remote"]);
3128

29+
XCUIElement* playButton = app.staticTexts[@"Play"];
30+
XCTAssertTrue([playButton waitForExistenceWithTimeout:30.0]);
31+
[playButton tap];
32+
33+
XCUIElement* chirpClosedCaption = app.staticTexts[@"[ Birds chirping ]"];
34+
XCTAssertTrue([chirpClosedCaption waitForExistenceWithTimeout:30.0]);
35+
36+
XCUIElement* buzzClosedCaption = app.staticTexts[@"[ Buzzing ]"];
37+
XCTAssertTrue([buzzClosedCaption waitForExistenceWithTimeout:30.0]);
38+
39+
XCUIElement* playbackSpeed1x = app.staticTexts[@"Playback speed\n1.0x"];
40+
XCTAssertTrue([playbackSpeed1x waitForExistenceWithTimeout:30.0]);
41+
[playbackSpeed1x tap];
42+
43+
XCUIElement* playbackSpeed5xButton = app.buttons[@"5.0x"];
44+
XCTAssertTrue([playbackSpeed5xButton waitForExistenceWithTimeout:30.0]);
45+
[playbackSpeed5xButton tap];
46+
47+
XCUIElement* playbackSpeed5x = app.staticTexts[@"Playback speed\n5.0x"];
48+
XCTAssertTrue([playbackSpeed5x waitForExistenceWithTimeout:30.0]);
49+
50+
// Cycle through tabs.
3251
for (NSString* tabName in @[ @"Asset", @"List example" ]) {
3352
NSPredicate* predicate = [NSPredicate predicateWithFormat:@"label BEGINSWITH %@", tabName];
3453
XCUIElement* unselectedTab = [app.staticTexts elementMatchingPredicate:predicate];
35-
if (![unselectedTab waitForExistenceWithTimeout:30.0]) {
36-
os_log_error(OS_LOG_DEFAULT, "%@", app.debugDescription);
37-
XCTFail(@"Failed due to not able to find unselected %@ tab", tabName);
38-
}
54+
XCTAssertTrue([unselectedTab waitForExistenceWithTimeout:30.0]);
3955
XCTAssertFalse(unselectedTab.isSelected);
4056
[unselectedTab tap];
4157

4258
XCUIElement* selectedTab = [app.otherElements
4359
elementMatchingPredicate:[NSPredicate predicateWithFormat:@"label BEGINSWITH %@", tabName]];
44-
if (![selectedTab waitForExistenceWithTimeout:30.0]) {
45-
os_log_error(OS_LOG_DEFAULT, "%@", app.debugDescription);
46-
XCTFail(@"Failed due to not able to find selected %@ tab", tabName);
47-
}
60+
XCTAssertTrue([selectedTab waitForExistenceWithTimeout:30.0]);
4861
XCTAssertTrue(selectedTab.isSelected);
4962
}
5063
}

packages/video_player/video_player/example/lib/main.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ class _ControlsOverlay extends StatelessWidget {
298298
Icons.play_arrow,
299299
color: Colors.white,
300300
size: 100.0,
301+
semanticLabel: 'Play',
301302
),
302303
),
303304
),

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ - (void)updatePlayingState;
5252

5353
static void* timeRangeContext = &timeRangeContext;
5454
static void* statusContext = &statusContext;
55+
static void* presentationSizeContext = &presentationSizeContext;
56+
static void* durationContext = &durationContext;
5557
static void* playbackLikelyToKeepUpContext = &playbackLikelyToKeepUpContext;
5658
static void* playbackBufferEmptyContext = &playbackBufferEmptyContext;
5759
static void* playbackBufferFullContext = &playbackBufferFullContext;
@@ -71,6 +73,14 @@ - (void)addObservers:(AVPlayerItem*)item {
7173
forKeyPath:@"status"
7274
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
7375
context:statusContext];
76+
[item addObserver:self
77+
forKeyPath:@"presentationSize"
78+
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
79+
context:presentationSizeContext];
80+
[item addObserver:self
81+
forKeyPath:@"duration"
82+
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
83+
context:durationContext];
7484
[item addObserver:self
7585
forKeyPath:@"playbackLikelyToKeepUp"
7686
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
@@ -286,6 +296,14 @@ - (void)observeValueForKeyPath:(NSString*)path
286296
[self updatePlayingState];
287297
break;
288298
}
299+
} else if (context == presentationSizeContext || context == durationContext) {
300+
AVPlayerItem* item = (AVPlayerItem*)object;
301+
if (item.status == AVPlayerItemStatusReadyToPlay) {
302+
// When the player item is ready, it still may not have determined its presentation size or
303+
// duration. When these properties are finally set, initialize the player.
304+
[self sendInitialized];
305+
[self updatePlayingState];
306+
}
289307
} else if (context == playbackLikelyToKeepUpContext) {
290308
if ([[_player currentItem] isPlaybackLikelyToKeepUp]) {
291309
[self updatePlayingState];

packages/video_player/video_player/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description: Flutter plugin for displaying inline video with other Flutter
33
widgets on Android, iOS, and web.
44
repository: https://github.com/flutter/plugins/tree/master/packages/video_player/video_player
55
issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+video_player%22
6-
version: 2.2.5
6+
version: 2.2.6
77

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

0 commit comments

Comments
 (0)